Guo Xiaoxing
Weibo: Guo Xiaoxing's Sina Weibo
Email:[email protected]
Blog: http://blog.csdn.net/allenwells
Github:https://github.com/allenwell
Sometimes we will see some good open source projects on GitHub and other websites, for these open source projects, we generally have read the source code and look at the effect of the two needs. At this time, we can import the project into Android Studio for source view and compile.
Before formally describing how to import third-party projects in Android Studio, let's introduce a lightweight implementation, the command line + text editor.
Source View
Source view You can use some text editing tools, recommend the use of sublime, lightweight and easy.
Source code compilation
Source compilation can be compiled using command line, following the Windows platform as an example, the following compilation process is demonstrated.
(1) command line jump to the project root, view and download the Gradle version used by the current project, execute the following command:
-v
(2) Download Gradle dependent, execute the following command:
gradlew clean
(3) Compile and generate the appropriate APK file and execute the following command:
gradlew build
A few points to note about the above commands:
- The Gradlew represents Gradle wrapper, a layer of gradle encapsulation.
- The Gradlew Build command will pack the APK for both debug and release two environments, and if you do not want to do so, you can use the assemble command:
- Gradlew Assembledebug: Compiling and Packaging debug APK
- Gradlew assemblerelease: Compiling and packaging release APK
In addition, the assemble command can be combined with product flavor to create a new task that implements the following functions:
- Allows you to build a variant version directly, such as Assembleflavor1debug.
- Allows you to build all the APK for the specified build type, for example Assembledebug will build the Flavor1debug and Flavor2debug two variant versions.
- Allow all apk to be built for the specified flavor, for example AssembleFlavor1 will build Flavor1debug and Flavor1release two variant versions.
Example
gradlew assemble360Release
Packaging release version for 360 channels
gradlew assemble360
Packed with 360 channel versions, this command generates release and debug versions of 360 channels.
gradlew assembleRelease`
Pack all release versions and this command will flavor all the release versions of all channels under product.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Android Studio Discovery Trail Series" IX: Gradle Project Building System (III): third-party Android studio project import: