Wie entfernt man eine Aktivität aus einem App-Flavor? Hier ist ein vereinfachtes Beispiel, ich habe eine App, die die folgenden zwei Geschmacksrichtungen (Paid und Free) hat. Die App ist klein und hat nur 3 Aktivitäten (MainActivity, ActivityOne und ActivityTwo). Die kostenpflichtige App benötigt keine Einschränkungen, da sie die gesamte Codebasis verwendet. Die kostenlose App erfordert jedoch, dass MainActivity und ActivityTwo für den Benutzer und nicht für ActivityOne verfügbar sind. Wie kann ich beim Kompilieren des Codes eine "Manifeste Zusammenführung" durchführen, so dass ActivityOne in der kostenlosen Version nicht vorhanden ist? Mit anderen Worten: Wie sollte src/free/AndroidManifest.xml erstellt werden, damit die kostenlose App ActivityOne nicht hat?Android - Entfernen von Activity from Flavour
Unten ist die build.gradle-Datei für die App:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.calculator"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
paid {
applicationId "com.example.paid"
resValue "string", "app_name", "Paid Calculator"
versionName "1.0-full"
}
free {
applicationId "com.example.free"
resValue "string", "app_name", "Free Calculator"
versionName "1.0-free"
}
}
sourceSets {
paid {
manifest.srcFile 'src/paid/AndroidManifest.xml'
}
free {
manifest.srcFile 'src/free/AndroidManifest.xml'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
}
Im Folgenden finden Sie die Manifest-Datei für die App Es befindet sich auf src/main/AndroidManifest.xml befindet:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.calculator">
<application
android:name="com.example.calculator.ui.activities.AppController"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".ui.activities.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activities.ActivityOne"
android:label="@string/title_activity_one"
android:parentActivityName=".ui.activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.activities.MainActivity" />
</activity>
<activity
android:name=".ui.activities.ActivityTwo"
android:label="@string/title_activity_two"
android:parentActivityName=".ui.activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.activities.MainActivity" />
</activity>
</application>
</manifest>
Verwenden Sie Build-Varianten – NaviRamyle