【Android Gradle 插件】AaptOptions 配置 ② ( additionalParameters 附加参数配置 | --rename-manifest-package 配置 )

Android Plugin DSL Reference 参考文档 :





一、–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 参数原型 :

       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'
    }

}

注意 : 参数以及参数选项 , 都使用逗号隔开 ;


在命令行中执行

gradlew :app:assembleDebug

命令 , 编译 debug 版本 apk ;


编译过程如下 :

D:\002_Project\002_Android_Learn\ClassLoader_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:\002_Project\002_Android_Learn\ClassLoader_Demo>

在这里插入图片描述
查看生成的 apk 文件 中的 AndroidManifest.xml 清单文件中的包名 , 已经被替换为 com.example.classloader_demo2 ;

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/han1202012/article/details/124578620