Compile the project APK in the Android source code environment, and the operation steps of writing Android.bp

If you want to compile the project APK in the Android source code environment, you have to add the Android.bp file to the project project. In the past, you used the .mk file. Now you find that bp is actually more convenient and practical.

1. First, you need to upload your project to the specified directory through git in the source code environment, and then write the bp file

2. Write the configuration file bp that needs to compile the apk, place Android.bp in the root directory, and libs in the root directory

3. An example of writing Android.bp file, the project includes jar package, so the jar package is compiled by java_import

java_import { 
name: "logcatzz_jar", (you must be careful not to use logcat when naming the jar package of logcat, otherwise it will be labeled as a jar name with another name by the system, which will cause it to be found and an error will be reported) jars: ["libs/ 
logcat.jar "], 

android_app { 
name: "project name", 
certificate: "platform", 
platform_apis: true, 
privileged: true, (will be output to the priv-app directory) 
system_ext_specific: true, 
optimize: { 
enabled: false, 
}, 
dxflags: ["--multi-dex"], 
dex_preopt: { 
enabled: false, 
}, 
srcs: [ 
"app/src/main/java/**/*.java", 
], resource_dirs: ["res", ], 
manifest: "AndroidManifest.xml", 
libs: [ 
"logcatzz_jar",  
], 
static_libs: [ 
"androidx.appcompat_appcompat", 
], 

After writing the bp file, you can start compiling the apk of the project, and execute the same command.

4. Start compiling apk 

$ source build/envsetup.sh 
$ lunch userdebug (the userdebug directory of your own source code, each project is different, find it yourself)
$ mmm project path (or execute mm in the current compiled project directory) 

5. Bugs encountered when compiling
1. The not found display style theme attribute 
needs to add "androidx.appcompat_appcompat" to static_libs in Android.bp

2. No such file for package registration
needs to check whether the name configured in bp is consistent with the stringname in the project

3. The missing dependencies of the jar package prompts that the dependency cannot be found. You can go to android\out\soong\.intermediates in the source code and then check whether the jar package name is consistent with the libs name in Android.bp
in your own project directory

4. The method symbol in the prompt code
first needs to confirm whether the method in the code is generated by the studio system itself. If it is generated by itself, it must be modified,
otherwise it will show that this method cannot be relied on.

Guess you like

Origin blog.csdn.net/qq_37870139/article/details/131485588