Customize AndroidManifest in different build types

I want to configure AndroidManifest in different build types. For example, in debug mode, I just want the operation to be exported.

Assume the main manifest:

/main/AndroidManifest.xml <application> <activity android:name="com.example.MainActivity" /> </application> 

Debugging:

 /debug/AndroidManifest.xml <application> <activity android:name="com.example.MainActivity" android:exported="true" /> </application> 

Example manifest (same as debugging):

 /example/AndroidManifest.xml <application> <activity android:name="com.example.MainActivity" android:exported="true" /> </application> 

In the debug manifest, I get Duplicate registration for activity com.example.MainActivity

This is why I created an example of an assembly type.

 /build.gradle android { buildTypes { example.initWith(buildTypes.debug) } } 

But it also does not work.

 [AndroidManifest.xml:17, AndroidManifest.xml:4] Trying to merge incompatible /manifest/application/activity[@name=com.example.MainActivity] element: <activity -- @android:name="com.example.MainActivity"> --</activity> --(end reached) <activity ++ @android:exported="true" ++ @android:name="com.example.MainActivity"> ++</activity> 

I am wondering if this will be a bug, a missing function (will be implemented in the future), or am I doing something wrong?

I know I can provide a different manifest in release and debugging (without it in /main ), but I don't think this is a good solution.

EDIT: The solution so far is to define a bool in resources and use it inside the main manifest. In debug resources, bool will be true , and in release false . This solution seems much better than duplicate manifests, but the question is still relevant.

+6
source share
2 answers

As of gradle plugin 0.10 it is finally supported. More on the new manifest merge: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger

Currently (gradle plugin 0.10) build.gradle is required for this additional configuration

 android { useOldManifestMerger false } 
+3
source

I know I can provide a different manifest in release and debugging (without one in / main), but I don't think this is a good solution.

Unfortunately, there is a limitation when merging a manifest, where you cannot define the same thing (action, service, receiver, etc.) in the main manifest and assembly type manifest. The solution is to define only specific non-line type elements in the main manifest and everything else in the assembly type manifest.

+1
source

Source: https://habr.com/ru/post/959401/


All Articles