2016-01-06 86 views
1

我目前正在使用Android Studio 2.0預覽4.我按照從tools.android.com的指南並從github測試了NDK samples。樣品的工作順利,但是當我實現它的SIPdroid項目,當我重建項目,它拋出這個錯誤:SIPdroid Android Studio ndk集成錯誤

Error:(78, 1) A problem occurred configuring project ':app'. Exception thrown while executing model rule: model.android Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl

,當我嘗試使用gradle這個項目同步它給出了這樣的錯誤:

Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'. Possible causes for this unexpected error include:

  • You are using JDK version 'java version "1.7.0_79"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle. Please update to a newer version (e.g. 1.7.0_67). Open JDK Settings
  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Android項目結構現在看起來像這樣。以前jni文件夾與java文件夾是分開的。 enter image description here

這裏是我的配置:

SIPdroid /應用/的build.gradle

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

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

     defaultConfig.with { 
      applicationId = "com.test.sipdroid" 
      minSdkVersion = 15 
      targetSdkVersion = 23 
      versionCode = 1 
      versionName = "1.0" 
     } 
    } 

    compileOptions.with { 
     sourceCompatibility = JavaVersion.VERSION_1_7 
     targetCompatibility = JavaVersion.VERSION_1_7 
    } 

    /* 
    * native build settings 
    */ 
    android.ndk { 
     moduleName = "SIPdroid" 
     /* 
     * Other ndk flags configurable here are 
     * cppFlags.add("-fno-rtti") 
     * cppFlags.add("-fno-exceptions") 
     * ldLibs.addAll(["android", "log"]) 
     * stl  = "system" 
     */ 
    } 

    android.sources { 
     main.java { 
      source { 
       srcDir 'src' 
      } 
     } 
     main.jni { 
      source { 
       srcDirs = [] 
      } 
     } 
     main.jniLibs { 
      source { 
       srcDirs = ['src/main/libs'] 
      } 
     } 
    } 

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

    android.productFlavors { 
     // for detailed abiFilter descriptions, refer to "Supported ABIs" @ 
     // https://developer.android.com/ndk/guides/abis.html#sa 
     create("arm") { 
      ndk.abiFilters.add("armeabi") 
     } 
     create("arm7") { 
      ndk.abiFilters.add("armeabi-v7a") 
     } 
     create("arm8") { 
      ndk.abiFilters.add("arm64-v8a") 
     } 
     create("x86") { 
      ndk.abiFilters.add("x86") 
     } 
     create("x86-64") { 
      ndk.abiFilters.add("x86_64") 
     } 
     create("mips") { 
      ndk.abiFilters.add("mips") 
     } 
     create("mips-64") { 
      ndk.abiFilters.add("mips64") 
     } 
     // To include all cpu architectures, leaves abiFilters empty 
     create("all") 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
} 

SIPdroid /的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

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

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

SIPdroid/gradle-wrapper.properties

#Mon Jan 04 16:06:26 PHT 2016 
distributionBase=GRADLE_USER_HOME 
distributionPath=wrapper/dists 
zipStoreBase=GRADLE_USER_HOME 
zipStorePath=wrapper/dists 
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 

SIPdroid/local.properties

ndk.dir=/path/Android/sdk/ndk-bundle 
sdk.dir=/path/Android/sdk 

回答

1

我剛剛解決了我的問題,通過增加這個我一部開拓創新的應用程序/文件的build.gradle不使用的gradle實驗版本('com.android.tools.build:gradle-實驗:0.4.0'),如谷歌樣本中所示。

該解決方案終於解決了問題NDKBuild Failure。這個額外的腳本使用ndkBuild構建你的jni文件。

應用/的build.gradle

sourceSets.main { 
     jniLibs.srcDir 'src/main/libs' // use the jni .so compiled from the manual ndk-build command 
     jni.srcDirs = [] //disable automatic ndk-build call 
    } 

    task ndkBuild(type: Exec) { 
//  commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath <-- Not working 
     commandLine '/home/user/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main/jni').absolutePath 
    } 

    tasks.withType(JavaCompile) { 
     compileTask -> compileTask.dependsOn ndkBuild 
    } 

SIPdroid /的build.gradle

dependencies { 
     classpath 'com.android.tools.build:gradle:1.2.3' 
} 

你還需要有一個空庫下的應用程序/ src目錄/主文件夾。我的錯誤是我將/ jni文件夾重命名爲/ libs。運行構建後,將編譯JNI的/ libs文件夾,以.so文件

app/src/main contents

jniLibs在你的Android項目結構圖如下所示。這是您的應用程序/ src目錄/主/庫在你的build.gradle腳本

enter image description here

我希望這有助於表示。