文章目录
- 一、--rename-manifest-package 重写 AndroidManifest 中的包名
Android Plugin DSL Reference 参考文档 :
- 文档主页 : https://google.github.io/android-gradle-dsl/2.3/
- AppExtension ( build.gradle#android 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.AppExtension.html
- build.gradle#android 模块配置文档 : android-gradle-dsl/2.3/com.android.build.gradle.AppExtension.html
- ProductFlavor ( build.gradle#android#defaultConfig 配置 ) 文档 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.ProductFlavor.html
- ProductFlavor#externalNativeBuild 配置 ( build.gradle#android#defaultConfig#externalNativeBuild 配置 ) : com.android.build.gradle.internal.dsl.ProductFlavor:externalNativeBuild
- ExternalNativeBuildOptions ( build.gradle#android#defaultConfig#externalNativeBuild 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.ExternalNativeBuildOptions.html
- NdkBuildOptions ( build.gradle#android#defaultConfig#externalNativeBuild#ndkBuild 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.NdkBuildOptions.html
- CmakeOptions ( build.gradle#android#defaultConfig#externalNativeBuild#cmake 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.CmakeOptions.html
- JackOptions ( build.gradle#android#defaultConfig#jackOptions 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.JackOptions.html
- AnnotationProcessorOptions ( 注解处理器配置 ) ( build.gradle#android#defaultConfig#javaCompileOptions配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AnnotationProcessorOptions.html
- NdkOptions ( build.gradle#android#defaultConfig#ndk 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.NdkOptions.html
- VectorDrawablesOptions ( build.gradle#android#defaultConfig#vectorDrawables 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.VectorDrawablesOptions.html
- BuildType ( build.gradle#android#buildTypes 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.BuildType.html
- SigningConfig ( build.gradle#android#signingConfigs 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.SigningConfig.html
- AaptOptions ( build.gradle#android#aaptOptions 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AaptOptions.html
- NDK 参考文档 : Add C and C Code to Your Project.
一、–rename-manifest-package 重写 AndroidManifest 中的包名
AaptOptions ( build.gradle#android#aaptOptions 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AaptOptions.html
aapt 的 --rename-manifest-package
参数配置的作用是 重写 AndroidManifest 中的包名 ;
–rename-manifest-package 参数原型 :
代码语言:javascript复制 Rewrite the manifest so that its package name is the package name
given here. Relative class names (for example .Foo) will be
changed to absolute names with the old package so that the code
does not need to change.
使用示例 : 默认设置的包名为 com.example.classloader_demo
,
在 " android # aaptOptions # additionalParameters " 中设置 '--rename-manifest-package com.example.classloader_demo2'
配置 ,
将 AndroidManifest.xml 清单文件中的包名修改为 com.example.classloader_demo2
;
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.classloader_demo"
}
aaptOptions {
additionalParameters '--rename-manifest-package', 'com.example.classloader_demo2'
}
}
注意 : 参数以及参数选项 , 都使用逗号隔开 ;
在命令行中执行
代码语言:javascript复制gradlew :app:assembleDebug
命令 , 编译 debug 版本 apk ;
编译过程如下 :
代码语言:javascript复制D: 02_Project 02_Android_LearnClassLoader_Demo>gradlew :app:assembleDebug
WARNING:: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
This repository is deprecated and it will be shut down in the future.
See http://developer.android.com/r/tools/jcenter-end-of-service for more information.
Currently detected usages in: root project 'ClassLoader_Demo', project ':app', project ':dex_demo', ...
BUILD SUCCESSFUL in 3s
54 actionable tasks: 4 executed, 50 up-to-date
D: 02_Project 02_Android_LearnClassLoader_Demo>
查看生成的 apk 文件 中的 AndroidManifest.xml 清单文件中的包名 , 已经被替换为 com.example.classloader_demo2
;