「Android/開発環境/AndroidStudio/ライブラリのAndroidManifest指定」の版間の差分
提供: 初心者エンジニアの簡易メモ
| (同じ利用者による、間の10版が非表示) | |||
| 行12: | 行12: | ||
元々のAndroidManifestは無効になって、置き換わってるっぽい。 | 元々のAndroidManifestは無効になって、置き換わってるっぽい。 | ||
| + | |||
| + | ==マージされたAndroidManifest.xml== | ||
| + | 以下にマージされたAndroidManifest.xmlが出力される | ||
| + | <pre> | ||
| + | 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 | ||
| + | </pre> | ||
| + | |||
| + | ==サンプル== | ||
| + | |||
| + | mainのsrc/main/AndroidManifest.xmlに以下を追加 | ||
| + | <pre> | ||
| + | <?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> | ||
| + | </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> | ||
| + | |||
| + | マージされたAndroidManifest.xml(app/build/intermediates/bundle_manifest/debug/bundle-manifest/AndroidManifest.xml) | ||
| + | <pre> | ||
| + | <?xml version="1.0" encoding="utf-8"?> | ||
| + | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| + | package="com.example.myapplication" | ||
| + | android:versionCode="1" | ||
| + | android:versionName="1.0" > | ||
| + | |||
| + | <uses-sdk | ||
| + | android:minSdkVersion="16" | ||
| + | android:targetSdkVersion="30" /> | ||
| + | |||
| + | <meta-data | ||
| + | android:name="hoge" | ||
| + | android:value="mylibrary" /> | ||
| + | |||
| + | <application | ||
| + | android:allowBackup="true" | ||
| + | android:appComponentFactory="androidx.core.app.CoreComponentFactory" | ||
| + | android:debuggable="true" | ||
| + | android:icon="@mipmap/ic_launcher" | ||
| + | android:label="@string/app_name" | ||
| + | android:roundIcon="@mipmap/ic_launcher_round" | ||
| + | android:supportsRtl="true" | ||
| + | android:testOnly="true" | ||
| + | android:theme="@style/AppTheme" > | ||
| + | <activity android:name="com.example.myapplication.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> | ||
| + | </pre> | ||
| + | |||
| + | ===上記サンプル失敗?=== | ||
| + | meta-dataがapplicationの外に出ていて、mylibraryにapplicationタグを追加するとエラーになった。 | ||
2020年10月23日 (金) 16:51時点における最新版
ライブラリの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"
マージされたAndroidManifest.xml(app/build/intermediates/bundle_manifest/debug/bundle-manifest/AndroidManifest.xml)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="30" />
<meta-data
android:name="hoge"
android:value="mylibrary" />
<application
android:allowBackup="true"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:debuggable="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:testOnly="true"
android:theme="@style/AppTheme" >
<activity android:name="com.example.myapplication.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>
上記サンプル失敗?
meta-dataがapplicationの外に出ていて、mylibraryにapplicationタグを追加するとエラーになった。
