gpt4 book ai didi

android - SIPdroid Android Studio ndk 集成错误

转载 作者:行者123 更新时间:2023-11-30 01:39:56 25 4
gpt4 key购买 nike

我目前正在使用 Android Studio 2.0 预览版 4。我已按照 tools.android.com 中的指南进行操作并测试了NDK samples来自github。示例工作顺利,但是当我在 SIPdroid 项目上实现它时,它会在我重建项目时抛出此错误:

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 project sync 时出现此错误:

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/app/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

最佳答案

我最近通过将此添加到我的原始 app/build.gradle 文件而不使用实验性 gradle 构建 ('com.android.tools.build:gradle-experimental: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'
}

您还需要在 app/src/main 下有一个空的 libs 文件夹。我的错误是我将/jni 文件夹重命名为/libs。运行构建后,它会把你的jni编译到/libs文件夹到.so文件

app/src/main contents

Android 项目结构 View 中的 jniLibs 将如下所示。这来自您的 app/src/main/libs,如您的 build.gradle 脚本中所示

enter image description here

希望对您有所帮助。

关于android - SIPdroid Android Studio ndk 集成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34627394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com