2016-01-08 49 views
5

我試圖建立與使用NDK模塊的項目。 但是Gradle構建會給出錯誤。如何使用gradle實驗性插件構建NDK模塊?

這是我的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爲' 融爲一體。未找到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" 
} 

的build.gradle(APP)

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(library2)

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(staggerdview)

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']) 
} 

回答

5

您應該使用實驗插件NDK目的:

所以你的build.gradle(主項目)看起來像:

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

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

和建設。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 { 
     // 
    } 
} 

不要忘記在您的local.properties文件中設置ndk.dir=ndk_path

UPDATE

更新android.buildTypes代碼在您的所有文件是這樣的:

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

我必須改變所有模塊的gradle這個像模塊{...}? – shj

+0

我想是的,因爲你正在使用'com.android.tools.build:gradle-experimental:0.4.0' gradle插件,它只支持''com.android.model.application''。 –

+0

我將所有模塊更改爲'com.android.model.library'而不是'com.android.library'。但突然它給了另一個錯誤 - 「錯誤:找不到屬性'android'在任務':library:androidJavadocs'。」你能幫我解釋這個錯誤的含義嗎? – shj

相關問題