2017-03-16 7 views
1

Mein Projekt enthält NDK. Und das ist die build.gradle Datei (App-Ebene).Wie behebt man den Gradle-Fehler?

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

model { 
    android { 
     compileSdkVersion = 25 
     buildToolsVersion = "25.0.1" 

     defaultConfig.with { 
      applicationId = "com.example.app" 
      minSdkVersion.apiLevel = 15 
      targetSdkVersion.apiLevel = 22 
      versionCode = 1 
      versionName = "1.0" 
     } 
    } 
    android.buildTypes { 
     release { 
      minifyEnabled = false 
      proguardFiles.add(file("proguard-rules.pro")) 
     } 
    } 
    android.ndk { 
     moduleName = "HelloARVideoNative" 
     cppFlags.add("-I${file("/home/obx/Downloads/EasyARSDKSamples/package/include")}".toString()) 
     cppFlags.add("-DANDROID") 
     cppFlags.add("-fexceptions") 
     cppFlags.add("-frtti") 
     stl = "gnustl_static" 
     ldLibs.add("log") 
     ldLibs.add("GLESv2") 
    } 
    android.productFlavors { 
     create("arm") { 
      ndk.with { 
       abiFilters.add("armeabi-v7a") 
      } 
     } 
    } 
    android.sources { 
     main { 
      jni { 
       dependencies { 
        library file("/home/obx/Downloads/EasyARSDKSamples/package/Android/libs/armeabi-v7a/libEasyAR.so") abi "armeabi-v7a" 
       } 
      } 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: '/home/obx/Downloads/EasyARSDKSamples/package/Android/libs') 
    compile 'com.android.support:appcompat-v7:25.1.1' 
    testCompile 'junit:junit:4.12' 
} 

Dies ist der Fehler, den ich erhalten tun:

Error:Gradle DSL method not found: 'library()'

Das ist, was ich versucht:

Das ist mein Top-Level-gradle Datei:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle-experimental:0.7.3' 
     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

Frage: Was möglicherweise das verursacht; und wie löst man?

Antwort

1

Ich bin nicht sicher, ob dies aber http://tools.android.com/tech-docs/new-build-system/gradle-experimental hilft sagt, dass es an einem gewissen Punkt Android Gradle Syntax für NDK Bibliotheken

The DSL for specifying dependencies on a specific library files have changed to follow Gradle's native dependency DSL.

Von ihrem examlpe geändert wurde sieht aus wie Sie Ihr Skript ändern müssen so etwas wie sein

model { 
    ... 
    repositories { 
     prebuilt(PrebuiltLibraries) { 
      binaries.withType(SharedLibraryBinary) { 
       sharedLibraryFile = file("/home/obx/Downloads/EasyARSDKSamples/package/Android/libs/armeabi-v7a/libEasyAR.so") 
       // or even 
       // sharedLibraryFile = file("/home/obx/Downloads/EasyARSDKSamples/package/Android/libs/${targetPlatform.getName()}/libEasyAR.so") 
      } 
     } 
    } 
    android.sources { 
     main { 
      jni { 
       dependencies { 
        library "prebuilt" 
       } 
      } 
     } 
    } 
} 

Sie können betrachten aslo jniLibs statt jni verwendet, die als

beschrieben

You can add native dependency to either 'jniLibs' or 'jni' source set. When dependency is added to "jniLibs" the native library will be package into the application/library, but it will not be used for compiling the JNI code.

+0

Danke für die Antwort, wird :) – OBX

+0

@OBX versuchen, lassen Sie uns wissen, ob dies tatsächlich das Problem war oder ist es etwas anderes – SergGr

0

Ich habe es gerade behoben, es war ein Problem mit der Verknüpfung von libEasyAR.so. Dies ist, wie mein build.gradle aussehen wie nach einigen Änderungen:

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

    model { 
     android { 
      compileSdkVersion = 25 
      buildToolsVersion = "25.0.2" 

      defaultConfig.with { 
       applicationId = "cn.easyar.samples.helloar" 
       minSdkVersion.apiLevel =15 
       targetSdkVersion.apiLevel = 22 
       versionCode = 1 
       versionName = "1.0" 
      } 
     } 
     android.buildTypes { 
      release { 
       minifyEnabled = false 
       proguardFiles.add(file("proguard-rules.pro")) 
      } 
     } 
     android.ndk { 
      moduleName = "HelloARNative" 
      cppFlags.add("-I${file("../../../package/include")}".toString()) 
      cppFlags.add("-DANDROID") 
      cppFlags.add("-fexceptions") 
      cppFlags.add("-frtti") 
      stl = "gnustl_static" 
      ldFlags.add("-LC:/Users/Me/Documents/AR_SDK/EasyAR/EasyARSDKSamples/Android/HelloARNative/app/src/main/jniLibs/armeabi-v7a") 
      ldLibs.add("log") 
      ldLibs.add("GLESv2") 
      ldLibs.add("EasyAR") 
     } 
     android.productFlavors { 
      create("arm") { 
       ndk.with { 
        abiFilters.add("armeabi-v7a") 
       } 
      } 
     } 
     repositories { 
      libs(PrebuiltLibraries) { 
       prebuilt { 
        headers.srcDir "src/main/jni" 
        binaries.withType(SharedLibraryBinary) { 
         sharedLibraryFile = file("src/main/libs/armeabi-v7a/libEasyAR.so") 
        } 
       } 
      } 
     } 
     android.sources { 
      main { 
       jniLibs { 
        dependencies { 
         library "prebuilt" 
        } 
       } 
      } 
     } 
    } 

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

Sie haben main die Bibliothek in einem Ordner libs unter Ihrem Ordner hinzuzufügen.

Hoffe, dass es helfen wird!

(Sorry für mein Englisch, ich bin ein französisch guy)

Verwandte Themen