包含带有风味android的库

And*_*lli 5 android gradle

我的应用程式gradle档案之前:

compile project(path: ':zblelib')

但是,当我在库中添加口味时,我的导入无法正常工作

我的口味:

flavorDimensions "dim"
    productFlavors {
        nocustomer {
            versionNameSuffix "-nocustomer"
            dimension = "dim"
        }
        customer001 {
            versionNameSuffix "-customer001"
            dimension = "dim"
        }
    }
Run Code Online (Sandbox Code Playgroud)

如何选择口味导入新库?

编辑:我的build.gradle

图书馆

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 26
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }

    flavorDimensions "dim"
    productFlavors {
        nocustomer {
            versionNameSuffix "-nocustomer"
            dimension = "dim"
        }
        customer001 {
            versionNameSuffix "-customer001"
            dimension = "dim"
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:27.1.1'
    compile 'com.android.support:design:27.1.1'
    compile 'com.android.support:support-v4:27.1.1'
    compile project(':criptolib-debug')
}
Run Code Online (Sandbox Code Playgroud)

应用程式

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultPublishConfig "nocustomerRelease"

    defaultConfig {
        applicationId "com.axesstmc.bleappphone"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 91
        versionName "8.2"
    }

    buildTypes {
        debug {
            minifyEnabled false
            //proguardFiles 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    ? ?
}
Run Code Online (Sandbox Code Playgroud)

xia*_*omi 7

应用程序存在的问题是它不知道要使用哪个库的样式。

关键字matchingFallbacks将告诉应用您要选择哪个库的样式。但是此关键字必须与Flavor一起使用。

我们必须在您的应用程序build.gradle上添加一个风味(+尺寸):

android {
    ...
    //flavorDimensions is mandatory with flavors. Use the same name on your 2 files to avoid other conflicts.
    flavorDimensions "dim"
    productFlavors {
        nocustomer{
            dimension "dim"

            // App and library's flavor have the same name.
            // MatchingFallbacks can be omitted
            matchingFallbacks = ["nocustomer"]
        }
        customerNb{
            dimension "dim"

            // Here the app and library's flavor are different
            // Matching fallbacks will select the library's flavor 'customer001'
            matchingFallbacks = ["customer001"]
        }
    }
    ...
}
dependencies {
    implementation project(':zblelib')
}
Run Code Online (Sandbox Code Playgroud)

这样,当您选择应用程序的样式时nocustomer,库的样式将自动选择nocustomer,而当您选择应用程序的样式时customerNb,库的样式将自动选择。customer001

聚苯乙烯

我使用implementation而不是compile,因为不推荐使用compile(请参阅此处