如何在Android Studio

时间:2017-11-17 04:35:49

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

我不是Android开发的新手,但我要添加原生版本。我想在Android工作室中手动设置.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')
}

1 个答案:

答案 0 :(得分:0)

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

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

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

会引起问题吗?也许