? ?
In general, using Gradle to build apk, there are two compilation settings, one is debug with the-debug mode, one is the final package-release mode. However, regardless of the type, the app must be signed on the installation to the virtual machine or device. When compiling to debug mode, use the Debug key. Compile to release mode with private key.
Whether you are compiling with Debug or release mode, you need run and build your module. This process will generate an APK that can be installed on the emulator or device. When you choose to use debug mode to compile an apk, this APK file is automatically signed by the SDK tools in the Build.gradle file debuggable true in the basic settings, using the Debug key. So that the APK can be installed immediately. You cannot distribute an application that is signed with the Debug key. When you choose to use release mode to compile an apk, this. APK is not signed, so you must manually sign with private key and use Keytool and Jarsigner to set the Build.gradle file in module.
Building in Debug Mode
On Windows platforms, Typethis command:
> Gradlew.bat assembledebug
On Mac OS and Linux platforms,type these commands:
$ chmod +x Gradlew
$./gradlew Assembledebug
The first command (chmod) adds the executionpermission to the Gradle wrapper script and are only necessary the first Timeyo U build this project from the command line
Compile the completed apk, in app/build/outputs/apk/
The AAR entered for any Lib Moudels is in lib/build/outputs/libs/.
To see a list of all available build tasks for Yourproject, type the This command:
$./gradlew Tasks
Building in Release Mode
? ? Before you start compiling an APK with release mode, be aware that you must sign with private key and then use the Zipalign tool.
There are two ways to compile a release mode apk.
The first (build unsigned): compiles the unsigned package under Release mode and then manually sign and align the package.
The second (build signed and aligned): Allows the build script to go to sign and align the package.
Build unsigned
On the Windows platforms, type this command:
> Gradlew.bat assemblerelease
On Mac OS and linuxplatforms, type the This command:
$./gradlew Assemblerelease
This creates the APK file in the project's Bin directory, with the name format <your_module_name>-unsigned.apk.
Note: At this point, the unsigned apk cannot be installed on the device until it is signed.
Once you have created a signed apk, the next step is to use the private key to sign and then use Zipalign to go to its bytes. How to achieve, please see my next article "Signing your Application"
Build signed and aligned
In the script configuration, the implementation of automatic signature, build.gradle the following wording.
...
Android {
...
Defaultconfig {...}
Signingconfigs {
Release {
StoreFile file ("Myreleasekey.keystore")
Storepassword "Password"
Keyalias "Myreleasekey"
Keypassword "Password"
}
}
Buildtypes {
Release {
...
Signingconfig Signingconfigs.release
}
}
}
...
The author has the words: if you need the Android Chinese API, please sweep the following QR code, your concern, is my motivation, do the technology, we are serious.
Android Chinese api:running Gradle Builds