日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

【Android Gradle 插件】ProductFlavor 配置 ( ProductFlavor#manifestPlaceholders 清单文件占位符配置 )

發布時間:2025/6/17 Android 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Android Gradle 插件】ProductFlavor 配置 ( ProductFlavor#manifestPlaceholders 清单文件占位符配置 ) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 一、ProductFlavor#manifestPlaceholders 清單文件占位符配置

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 文檔 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.ProductFlavor.html

  • ProductFlavor#externalNativeBuild 配置 : com.android.build.gradle.internal.dsl.ProductFlavor:externalNativeBuild

  • ExternalNativeBuildOptions 文檔位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.ExternalNativeBuildOptions.html

  • NdkBuildOptions 文檔位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.NdkBuildOptions.html

  • CmakeOptions 文檔位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.CmakeOptions.html

  • JackOptions 文檔位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.JackOptions.html

  • AnnotationProcessorOptions ( 注解處理器配置 ) 文檔位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AnnotationProcessorOptions.html

  • NDK 參考文檔 : Add C and C++ Code to Your Project.





一、ProductFlavor#manifestPlaceholders 清單文件占位符配置



ProductFlavor 參考文檔 : com.android.build.gradle.internal.dsl.ProductFlavor.html


ProductFlavor#manifestPlaceholders 配置 , 用于配置 manifest 的占位符 , 該配置項是 Map<String, Object> 類型的 ;


在 build.gradle 的 ProductFlavor defaultConfig 配置項中 , 設置清單文件占位符屬性 , 為其設置一個 Map<String, Object> 類型的屬性 ;

代碼示例 :

android {defaultConfig {manifestPlaceholders = [name: 'Tom']}

完整代碼 :

plugins {id 'com.android.application' }android {compileSdkVersion 31buildToolsVersion "30.0.3"defaultConfig {applicationId "com.example.ad_id_test"minSdkVersion 18targetSdkVersion 31versionCode 1versionName "1.0"testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"manifestPlaceholders = [name: 'Tom']}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'}}compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}}dependencies {implementation 'androidx.appcompat:appcompat:1.4.1'implementation 'com.google.android.material:material:1.5.0'implementation 'androidx.constraintlayout:constraintlayout:2.1.3'testImplementation 'junit:junit:4.+'androidTestImplementation 'androidx.test.ext:junit:1.1.3'androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }

清單文件配置 : 在下面的 meta-data 標簽中 , 使用了 ${name} 引用了 build.gradle 中定義的 manifestPlaceholders = [name: 'Tom'] , 在合并清單文件時 , 會自動使用 Tom 替換上述 ${name} 引用 ;

<meta-data android:name="student" android:value="${name}" />

完整 AndroidManifest.xml 清單文件配置 :

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.ad_id_test"><uses-permission android:name="com.google.android.gms.permission.AD_ID"/><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.AD_ID_Test"><meta-data android:name="student" android:value="${name}" /><activity android:name=".MainActivity"android:exported="false"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

AndroidManifest.xml 清單文件 切換到 Merged Manifest 模式 , 可以看到合并后的 清單文件 , 其中 <meta-data> 標簽 , 由

<meta-data android:name="student" android:value="${name}" />

變成了

<meta-data android:name="student" android:value="Tom" />

樣式 , ${name} 被 Tom 替換了 ;

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的【Android Gradle 插件】ProductFlavor 配置 ( ProductFlavor#manifestPlaceholders 清单文件占位符配置 )的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。