【问题标题】:How to set .mk file location path in Android Studio如何在 Android Studio 中设置 .mk 文件位置路径
【发布时间】:2017-11-17 04:35:48
【问题描述】:

我对 Android 开发并不陌生,但我正在添加原生构建。我想在 Android Studio 中手动设置 .mk 文件位置,但我想不通。我试过这个'

    externalNativeBuild {
        ndkBuild {
            path 'jni/Android.mk'
        }
}

但这只是被 gradle build 忽略了。有人能告诉我怎么做吗?以下是我的完整 gradle 文件。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "my application full name"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        ndk {
            moduleName "nativeegl"
            ldLibs "log", "android", "EGL", "GLESv1_CM"
        }
    }

    externalNativeBuild {
        ndkBuild {
            path 'jni/Android.mk'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile files('libs/Vuforia.jar')
}

【问题讨论】:

  • 确保将此块作为 android 块的子块。
  • @Alex Cohn,我做到了。但它被原始设置覆盖。我知道有一种方法可以从 Android Studio 手动指向 .mk 文件,我只是不记得如何了。
  • 你怎么知道的?您看到了哪些错误消息?
  • Android Studio、android插件、gradle插件哪个版本?您是否尝试删除项目的 .externalNativeBuild 目录(如果有)并重新同步?
  • @Alex Cohn,我收到错误消息:Gradle project ndkBuild.path is C:\Users\project_path\app\src\main\jni\make_directory\Android.mk 但该文件不存在.我知道是因为我将文件从其原始文件夹中移出以调试其他问题。

标签: android android-ndk java-native-interface android.mk


【解决方案1】:

删除目录C:\Users\project_path\app\.externalNativeBuild 并在工具菜单中强制同步 Gradle。如果这还不够,我还有更激进的措施。

顺便说一句,这个块已经过时了:

ndk {
     moduleName "nativeegl"
     ldLibs "log", "android", "EGL", "GLESv1_CM"
}

它会导致问题吗?也许吧。

【讨论】:

  • 感谢您为解决此问题所做的努力。不幸的是,这并没有解决问题。我一直在谷歌搜索并寻找 SO 答案,但我还没有找到解决方案。
  • 如果你想要一个激进的措施,退出 AS,删除你的 $HOME\.gradle 目录,删除 C:\Users\project_path\app\.externalNativeBuild 和 C:\Users\project_path\.gradle 和C:\Users\project_path.idea 和 C:\Users\project_path 下的所有 .iml 文件。现在,重新打开项目。
猜你喜欢
  • 1970-01-01
  • 2013-11-05
  • 1970-01-01
  • 2022-01-22
  • 2011-01-08
  • 2015-11-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多