6

我正在尝试使用使用 NDK 的模块构建项目。但是 Gradle 构建会出错。

这是我的 build.gradle(主项目)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

   //     classpath 'com.android.tools.build:gradle-experimental:0.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

当我尝试使用此 gradle:1.5.0 时,它会给出错误“错误:(17, 0) 未找到 ID 为 'com.android.model.application' 的插件。”

另一方面,如果我使用 gradle-experimental:0.1.0 它会给出错误“错误:(17, 0) 未找到 ID 为 'com.android.application' 的插件。”

我该如何解决这个错误?我的项目中有几个模块。如何设置满足所有模块的 gradle?

编辑:

build.gradle(主项目)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
//        classpath 'com.android.tools.build:gradle:1.5.0'

        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

def isReleaseBuild() {
    return isTag() && !isSnapshot()
}

def isSnapshot() {
    return version.contains("SNAPSHOT")
}

boolean isTravis() {
    return System.getenv('TRAVIS_BUILD_NUMBER') ? true : false
}

boolean isTag() {
    def tag = System.getenv('TRAVIS_TAG')
    return !(tag == null || tag.isEmpty())
}

def buildNumber() {
    return System.getenv('TRAVIS_BUILD_NUMBER') ?: "0"
}

构建.gradle(应用程序)

apply plugin: 'com.android.model.application'

repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/releases"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/staging"
    }
}

model {

    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            applicationId = "com.ToxicBakery.viewpager.transforms"
            minSdkVersion.apiLevel = 16
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:cardview-v7:22.0.0'
    compile 'info.hoang8f:fbutton:1.0.5'
    compile project(':contextMenu')
    compile project(':library')
    compile project(':library2')
    compile project(':titanic')
    compile files('libs/universal-image-loader-1.9.4.jar')
    compile project(':staggeredview')
    compile project(':min3d')
}

build.gradle(上下文菜单)

apply plugin: 'com.android.model.library'
model {
    android {
        compileSdkVersion = 21
        buildToolsVersion = "21.1.2"

        defaultConfig.with {
            minSdkVersion.apiLevel = 11
            targetSdkVersion.apiLevel = 21
        }

    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.nineoldandroids:library:2.4.0'
}

build.gradle(库)

apply plugin: 'com.android.model.library'
apply plugin: 'signing'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            minSdkVersion.apiLevel = 13
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }

    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}
dependencies {
    compile 'com.android.support:support-v13:22.1.1'
}

apply from: '../maven_push.gradle'

build.gradle(库2)

apply plugin: 'com.android.model.library'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }

    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
}

build.gradle(min3d)

apply plugin: 'com.android.model.library'
model {
    android {
        compileSdkVersion = 15
        buildToolsVersion = "21.0.2"
        defaultConfig.with {
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        debug {

        }
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.productFlavors {
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

build.gradle(交错视图)

apply plugin: 'com.android.model.library'

dependencies {
    compile 'com.android.support:support-v4:19.1.+'
}

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }

    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

build.gradle(泰坦尼克号)

apply plugin: 'com.android.model.library'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = '22.0.1'

        defaultConfig.with {
            minSdkVersion.apiLevel  = 11
            targetSdkVersion.apiLevel  = 19
            versionCode = 1
            versionName = "1.0"
        }
    }

    android.buildTypes{
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:20.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
4

1 回答 1

5

您应该为 NDK 目的使用实验性插件:

所以你的 build.gradle(Main Project) 看起来像:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle(app) 看起来像:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"

        defaultConfig.with {
            applicationId = "com.sample.codecator"
            minSdkVersion.apiLevel = 19
            targetSdkVersion.apiLevel = 19
        }
    }
}

如果您正在使用任何库模块,那么它build.gradle看起来像:

apply plugin: 'com.android.model.library'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"

        defaultConfig.with {
            minSdkVersion.apiLevel = 19
            targetSdkVersion.apiLevel = 19
        }
    }
}

您应该将以下内容排除在外android{...}

android.buildTypes
android.sources
android.productFlavors

喜欢:

model {

android {
            compileSdkVersion = 23
            buildToolsVersion = "23.0.2"

            defaultConfig.with {
                minSdkVersion.apiLevel = 19
                targetSdkVersion.apiLevel = 19
            }


   android.buildTypes {
    release {
        minifyEnabled = false
        proguardFiles.add(file("proguard-rules.pro"))
         }
     }
    android.productFlavors {
       //
    }

    android.sources {
        //
    }
}

不要忘记ndk.dir=ndk_path在您的local.properties文件中设置。

更新

像这样更新android.buildTypes所有文件中的代码:

android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file("proguard-rules.pro"))
        }
    }
于 2016-01-08T05:02:33.437 回答