简体   繁体   English

SIPdroid Android Studio NDK集成错误

[英]SIPdroid Android Studio ndk integration error

I'm currently using Android Studio 2.0 preview 4. I have followed the guide from tools.android.com and tested NDK samples from github. 我目前正在使用Android Studio 2.0预览版4。我已遵循tools.android.com上的指南,并从github测试了NDK示例 The samples worked without a hitch, but when I implemented it on the SIPdroid project, it throws this error when I rebuild the project: 这些示例工作顺利,但是当我在SIPdroid项目上实现它时,在重建项目时会抛出此错误:

Error:(78, 1) A problem occurred configuring project ':app'. 错误:(78,1)配置项目':app'时发生问题。 Exception thrown while executing model rule: model.android Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl 执行模型规则时抛出异常:model.android无法设置只读属性:类minSdkVersion:com.android.build.gradle.managed.ProductFlavor_Impl

when I try to use gradle project sync it gives this error: 当我尝试使用gradle项目同步时,出现此错误:

Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'. 错误:无法加载类“ 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"'. 您正在使用JDK版本“ java版本“ 1.7.0_79””。 Some versions of JDK 1.7 (eg 1.7.0_10) may cause class loading errors in Gradle. JDK 1.7的某些版本(例如1.7.0_10)可能会导致Gradle中的类加载错误。 Please update to a newer version (eg 1.7.0_67). 请更新到较新的版本(例如1.7.0_67)。 Open JDK Settings 打开JDK设置
  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) Gradle的依赖项缓存可能已损坏(这有时会在网络连接超时后发生。)重新下载依赖项并同步项目(需要网络)
  • The state of a Gradle build process (daemon) may be corrupt. Gradle构建过程(守护程序)的状态可能已损坏。 Stopping all Gradle daemons may solve this problem. 停止所有Gradle守护程序可以解决此问题。 Stop Gradle build processes (requires restart) 停止Gradle构建过程(需要重新启动)
  • 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. 您的项目可能使用的第三方插件与该项目中的其他插件或该项目要求的Gradle版本不兼容。
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes. 如果Gradle进程损坏,您也可以尝试关闭IDE,然后终止所有Java进程。

Android project structure now looks like this. Android项目结构现在看起来像这样。 previously the jni folder is separated from the java folder. 以前,jni文件夹与java文件夹是分开的。 在此处输入图片说明

Here's my config: 这是我的配置:

SIPdroid/app/build.gradle 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 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 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 SIPdroid / local.properties

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

I just recently solved my issue by adding this to my orignal app/build.gradle file without using the experimental gradle build ('com.android.tools.build:gradle-experimental:0.4.0') as indicated in the google samples. 我刚刚解决了我的问题,方法是将其添加到我的原始app / build.gradle文件中,而不使用google示例中所示的实验性gradle构建('com.android.tools.build:gradle-experimental:0.4.0')。

This solution finally solved the issue NDKBuild Failure . 此解决方案最终解决了NDKBuild失败问题。 This additional script builds your jni files using ndkBuild. 这个附加脚本使用ndkBuild来构建jni文件。

app/build.gradle 应用程序/的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 SIPdroid /的build.gradle

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

You also need to have an empty libs folder under app/src/main. 您还需要在app / src / main下有一个空的libs文件夹。 My mistake was that I renamed the /jni folder to /libs. 我的错误是我将/ jni文件夹重命名为/ libs。 After running the build, it will compile your jni to the /libs folder to .so files 运行构建后,它将把jni到/ libs文件夹编译为.so文件

app / src /主要内容

jniLibs in your Android project structure view will look like this. Android项目结构视图中的jniLibs将如下所示。 This is from your app/src/main/libs as indicated in your build.gradle script 这来自build / gradle脚本中指示的app / src / main / libs

在此处输入图片说明

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM