「Android/開発環境/AndroidStudio/ライブラリのAndroidManifest指定」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→マージされたAndroidManifest.xml) |
(→マージされたAndroidManifest.xml) |
||
行21: | 行21: | ||
</pre> | </pre> | ||
− | + | ==サンプル== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
mainのsrc/main/AndroidManifest.xmlに以下を追加 | mainのsrc/main/AndroidManifest.xmlに以下を追加 | ||
行66: | 行55: | ||
</manifest> | </manifest> | ||
+ | </pre> | ||
+ | |||
+ | mylibrary | ||
+ | のsrc/main/AndroidManifest.xmlに以下を追加 | ||
+ | <pre> | ||
+ | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
+ | package="com.example.mylibrary"> | ||
+ | |||
+ | <meta-data | ||
+ | android:name="hoge" | ||
+ | android:value="mylibrary" /> | ||
+ | |||
+ | </manifest> | ||
+ | </pre> | ||
+ | |||
+ | main側のbuild.gradle | ||
+ | <pre> | ||
+ | apply plugin: 'com.android.application' | ||
+ | |||
+ | android { | ||
+ | compileSdkVersion 30 | ||
+ | buildToolsVersion "30.0.1" | ||
+ | |||
+ | defaultConfig { | ||
+ | applicationId "com.example.myapplication" | ||
+ | minSdkVersion 16 | ||
+ | targetSdkVersion 30 | ||
+ | versionCode 1 | ||
+ | versionName "1.0" | ||
+ | |||
+ | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
+ | } | ||
+ | buildTypes { | ||
+ | release { | ||
+ | minifyEnabled false | ||
+ | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | dependencies { | ||
+ | implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
+ | implementation project(':mylibrary') | ||
+ | implementation 'androidx.appcompat:appcompat:1.2.0' | ||
+ | implementation 'androidx.constraintlayout:constraintlayout:2.0.2' | ||
+ | testImplementation 'junit:junit:4.12' | ||
+ | androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
+ | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
+ | |||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | mylibrary側のbuild.gradle | ||
+ | <pre> | ||
+ | apply plugin: 'com.android.library' | ||
+ | |||
+ | android { | ||
+ | compileSdkVersion 30 | ||
+ | buildToolsVersion "30.0.1" | ||
+ | |||
+ | defaultConfig { | ||
+ | minSdkVersion 16 | ||
+ | targetSdkVersion 30 | ||
+ | versionCode 1 | ||
+ | versionName "1.0" | ||
+ | |||
+ | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
+ | consumerProguardFiles "consumer-rules.pro" | ||
+ | } | ||
+ | |||
+ | buildTypes { | ||
+ | release { | ||
+ | minifyEnabled false | ||
+ | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | sourceSets { | ||
+ | main { | ||
+ | manifest.srcFile 'src/main/AndroidManifest.xml' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | dependencies { | ||
+ | implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
+ | implementation 'androidx.appcompat:appcompat:1.2.0' | ||
+ | testImplementation 'junit:junit:4.12' | ||
+ | androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
+ | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
+ | |||
+ | } | ||
+ | </pre> | ||
+ | settings.gradleの設定 | ||
+ | <pre> | ||
+ | include ':mylibrary' | ||
+ | include ':app' | ||
+ | rootProject.name = "My Application" | ||
</pre> | </pre> |
2020年10月23日 (金) 13:23時点における版
ライブラリのbuild.gradleに以下を記述
android { sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' } } }
そのファイルがあるdirのsrc/main/AndroidManifest.xmlにAndroidManifestを記述すると、
元々のAndroidManifestは無効になって、置き換わってるっぽい。
マージされたAndroidManifest.xml
以下にマージされたAndroidManifest.xmlが出力される
app/build/intermediates/bundle_manifest/debug/bundle-manifest/AndroidManifest.xml app/build/intermediates/merged_manifests/debug/AndroidManifest.xml /app/build/intermediates/instant_app_manifest/debug/AndroidManifest.xml
サンプル
mainのsrc/main/AndroidManifest.xmlに以下を追加
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="hoge" android:value="main" /> <meta-data android:name="hoge2" android:value="mainmain" /> </application> </manifest>
mylibrary のsrc/main/AndroidManifest.xmlに以下を追加
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mylibrary"> <meta-data android:name="hoge" android:value="mylibrary" /> </manifest>
main側のbuild.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 30 buildToolsVersion "30.0.1" defaultConfig { applicationId "com.example.myapplication" minSdkVersion 16 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation project(':mylibrary') implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
mylibrary側のbuild.gradle
apply plugin: 'com.android.library' android { compileSdkVersion 30 buildToolsVersion "30.0.1" defaultConfig { minSdkVersion 16 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' } } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.2.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
settings.gradleの設定
include ':mylibrary' include ':app' rootProject.name = "My Application"