我无法应用自定义脚本插件

时间:2019-01-09 09:30:16

标签: android gradle

我已经建立了buildsystem目录,并在该目录中创建了文件library.gradle和config.gradle file.code,如下所示:

config.gradle

ext.configuration = [

  applicationId       : bicker.techfour.com.bicker,
  versionMajor                : 1,
  versionMinor                : 0,
  versionPatch                : 2,
  versionClassifier           : "",
  minimumSdkVersion           : 14,
  compileSdkVersion           : 23,
  targetSdkVersion            : 23,
  buildToolsVersion           : "23.0.2"
]

def configuration = ext.configuration;

ext.buildVersionCode = {
    return configuration.minimumSdkVersion * 10000000 + configuration.versionMajor * 10000 + configuration.versionMinor * 100 + configuration.versionPatch
}

ext.buildVersionName = {
    String versionName = ext.buildVersionNameWithoutClassifier();
    if (configuration.versionClassifier != null && !configuration.versionClassifier.isEmpty()) {
        versionName = versionName + "-" + configuration.versionClassifier
    }
    return versionName;
}

library.gradle

ext.version = [
    support          : "23.2.1",
    rxjava           : "1.1.0",
    rxandroid        : "1.1.0",

]

def version = ext.version;

ext.library = [
    support_compat   :
            "com.android.support:appcompat-v7:${version.support}",
    support_design   : "com.android.support:design:${version.support}",
    rxjava           :
            "io.reactivex:rxjava:${version.rxjava}",
    rxandroid        :
            "io.reactivex:rxandroid:${version.rxandroid}",
]

现在app.gradle文件:

apply plugin: 'com.android.application'

android 

{

compileSdkVersion 28
defaultConfig {
    applicationId "bicker.techfour.com.bicker"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    flavorDimensions "version"
    productFlavors {
        prod {
            dimension "version"
            applicationId = "bicker.techfour.com.bicker"
            versionName = "1.0"
        }

        mock {
            dimension "version"
            applicationId = "bicker.techfour.com.bicker"
            versionName = "1.0"
        }

    }


}



apply from: "$rootProject.projectDir/buildsystem/library.gradle"
def library = ext.library
dependencies {
    compile                 fileTree(dir: 'libs', include: ['*.jar'])
    compile                 "${library.support_compat}"
    compile                 "${library.support_design}"
    compile                 "${library.rxjava}"
    compile                 "${library.rxandroid}"
    // rest of dependencies
}
apply from: "$rootProject.projectDir/buildsystem/config.gradle"
def configuration = ext.configuration

android {
    compileSdkVersion configuration.compileSdkVersion
    buildToolsVersion configuration.buildToolsVersion

    defaultConfig {
        applicationId configuration.applicationId
        minSdkVersion configuration.minimumSdkVersion
        targetSdkVersion configuration.targetSdkVersion
        versionCode buildVersionCode()
        versionName buildVersionName()
    }
}

}

1 个答案:

答案 0 :(得分:0)

从您的问题和评论中还不清楚您的项目布局如何,但是我认为您应该有类似的东西:

$rootProjectDir
    |- build.gradle
    |
    |-app/
    |   |- build.gradle
    |  
    |-buildsystem/
    |    |- config.gradle
    |    |- library.gradle 

然后在您的应用build.gradle文件中,可以像以前一样包含两个gradle文件:

apply from: "$rootProject.projectDir/buildsystem/config.gradle"
apply from: "$rootProject.projectDir/buildsystem/library.gradle"