How to create an Android gradle project that contains modules with various compileSdkVersion, targetSdkVersion and minSdkVersion?

My Android library project consists of four modules:

  • Project
    • base
    • factory
    • v14
    • v18

Here is a screenshot of this installation from IntelliJ:

modules

My modules use very specific Android SDK level settings:

  • base
    • compileSdkVersion 19
    • minSdkVersion 14
    • targetSdkVersion 19
  • factory
    • compileSdkVersion 19
    • minSdkVersion 14
    • targetSdkVersion 19
  • v14
    • compileSdkVersion 17
    • minSdkVersion 14
    • targetSdkVersion 17
  • v18
    • compileSdkVersion 18
    • minSdkVersion 18
    • targetSdkVersion 18

When newer versions of Android are released, the base and factory modules can have compileSdkVersion and targetSdkVersion . However, v14 and v18 both absolutely cannot follow this example.

My modules depend on each other in a special way:

  • base
    • independent of any other module
  • factory
    • depends on the base, v14 and v18
  • v14
    • depends on the base
  • v18
    • depends on the base

So, when I go to build my project, I get this error:

 Error:Gradle: Execution failed for task ':v14:processReleaseManifest'. > Manifest merging failed. See console for more info. 

When creating through the terminal using ./gradlew build --stacktrace I get a little more information:

 :v14:processReleaseManifest [/blahblah/project/v14/build/exploded-aar/blahblah/base/unspecified/AndroidManifest.xml:2] Main manifest has <uses-sdk android:targetSdkVersion='17'> but library uses targetSdkVersion='19' :v14:processReleaseManifest FAILED 

And here is my v14 AndroidManifest.xml file:

 <?xml version="1.0" encoding="utf-8"?> <manifest package="com.example.v14"> <application /> </manifest> 

(My base AndroidManifest.xml file is almost exactly identical)

 <?xml version="1.0" encoding="utf-8"?> <manifest package="com.example"> <application /> </manifest> 

This mistake does not make much sense to me. First of all, I do not specify version levels in any of the four different AndroidManifest.xml files (and instead, these values ​​are inherited through four different build.gradle ).

Secondly, I don’t have a “main manifest”. The base module is probably the closest to what I need, and therefore, how exactly the v14 module turned out to be the “main manifest”, I find it rather confusing.

Finally, if this project setup is not possible, then I am in shock. This module configuration is absolutely trivial to set up in an Eclipse style project. This is how I created the library for several months.

By the way, my ultimate goal is to have all this compiled to a single .jar file, which my current Eclipse-style project can do. I'm just trying to completely switch to gradle and not stay on a sunken ship ...

Any ideas? If necessary, I can place my various gradle files ( build.gradle , settings.gradle ...). Just trying to completely overload this post.

Edit (May 27, 2014)

A screenshot of my module configuration has been added to the top of this post.

+6
source share
1 answer

If you use flavors according to the Gradle plugin user guide :

defaultConfig provides a basic configuration for all flavors and each flavor can override any value.

For example, you might have the following setting in the build.gradle file:

  android { ... defaultConfig { ... compileSdkVersion 19 minSdkVersion 14 targetSdkVersion 19 } productFlavors { base { compileSdkVersion 19 minSdkVersion 14 targetSdkVersion 19 } factory { compileSdkVersion 19 minSdkVersion 14 targetSdkVersion 19 } v14 { compileSdkVersion 17 minSdkVersion 14 targetSdkVersion 17 } v18 { compileSdkVersion 18 minSdkVersion 18 targetSdkVersion 18 } } } 

In addition, you do not need to specify the package name in the manifest. You can install them like this:

 android { ... productFlavors { base { packageName "com.example" ... } v14 { packageName "com.example.v14" ... } ... } } 
0
source

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


All Articles