简体   繁体   中英

How to build Android gradle project that contains modules with different compileSdkVersion, targetSdkVersion, and minSdkVersion?

My Android library project is made up of four modules:

  • project
    • base
    • factory
    • v14
    • v18

Here's a screenshot of this setup from IntelliJ:

模块

My modules utilize 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

As newer versions of Android are released, the base and factory modules can have their compileSdkVersion and targetSdkVersion levels follow along. However, v14 and v18 both absolutely can't follow suit with this.

My modules depend on each other in very specific ways:

  • base
    • does not depend on any other module
  • factory
    • depends on base, v14, and v18
  • v14
    • depends on base
  • v18
    • depends on base

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

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

When building via terminal using ./gradlew build --stacktrace , I get a little bit 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's 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 nearly exactly identical)

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

    <application />

</manifest>

This error doesn't make very much sense to me. First of all, I don't specify version levels in any of my four different AndroidManifest.xml files (and I instead let those values be inherited through my four different build.gradle files).

Secondly, I don't have a "Main manifest". The base module is probably the closest thing I have to that, and so how exactly the v14 module ended up as the "Main manifest" I find pretty confusing.

Finally, if this project setup isn't possible, then I'm shocked. This module configuration is absolutely trivial to set up in an Eclipse-style project. It's how I've been building the library for months now.

By the way, my end goal is for this to all compile down to a single .jar file, which my current Eclipse-style project can do. It's just that I'm trying to completely migrate over to gradle and not be left behind on a sinking ship...

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

Edit (May 27th, 2014)

Added a screenshot of my module configuration to the beginning of this post.

If you are using flavours according to Gradle plugin user guide :

defaultConfig provides the base configuration for all flavors and each flavor can override any value.

For example you can have the following setup in your 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
            }
        }
    }

Moreover you don't need to set the package name in the manifest either. You can set them like the following:

android {
    ...

    productFlavors {
        base {
            packageName "com.example"
            ...
        }

        v14 {
            packageName "com.example.v14"
            ...
        }
        ...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM