2

I am not new to Android development but I am to adding native build. I would like to set the .mk file location manually in Android studio but I couldn't figure it out. I tried this'

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

but that simply is ignored by gradle build. Can someone tell me how? Following is my full gradle file.

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')
}
The_Martian
  • 3,684
  • 5
  • 33
  • 61
  • Make sure you put this block as a child of the **android** block. – Alex Cohn Nov 17 '17 at 04:47
  • @Alex Cohn, I did. But it is being overridden by the original setting. I know there is a way to point the .mk file manually from Android studio, I just can't remember how. – The_Martian Nov 17 '17 at 06:00
  • How do you know? What error messages do you see? – Alex Cohn Nov 17 '17 at 07:03
  • Which version of Android Studio, the android plugin, and the gradle plugin? Did you try deleting the `.externalNativeBuild` directory for your project (if there was one) and re-syncing? – Michael Nov 17 '17 at 07:04
  • @Alex Cohn, I am getting Error:Gradle project ndkBuild.path is C:\Users\project_path\app\src\main\jni\make_directory\Android.mk but that file doesn't exist. I know because I moved the file from it's original folder to debug other issue. – The_Martian Nov 17 '17 at 07:11
  • @Michael, I am on Android 2.3.3, Android plugin 2.3.3 and gradle 3.3. I did delete it. – The_Martian Nov 17 '17 at 07:44
  • Well, it works for me both with [Android Studio 2.3.1, android plugin 2.3.3, gradle plugin 3.3] and [Android Studio 3.0, android plugin 3.0.0, gradle plugin 4.1]. Can you post your `build.gradle` file? – Michael Nov 17 '17 at 07:47
  • @Michael, I did. – The_Martian Nov 17 '17 at 08:20
  • That script works for me. Are you 100% sure that this is the project you're syncing? Does the project have any dependencies that also use the NDK? Have you tried searching your entire drive for any files that contain the string `make_directory` to see where it might originate from? – Michael Nov 17 '17 at 09:34
  • Yes it does work, but I have previously changed the Android.mk file path to my former folder manually so mine is not working. So now ndk is still looking on that folder. The externalnativebuild is simply being ignored. I need to update the ndk to point to the new folder that the Android.mk is located. But I don't remember how I did that in Android studio. – The_Martian Nov 17 '17 at 10:03

1 Answers1

0

Delete directory C:\Users\project_path\app\.externalNativeBuild and force Sync Gradle in the Tools menu. If this is not enough, I have more radical measures in stock.

By the way, this block is obsolete:

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

Could it cause problems? Maybe.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I appreciate your effort to solve this problem. Unfortunately, that didn't fix it. I have been Googling and looking for SO answers, but I haven't found the solution yet. – The_Martian Nov 18 '17 at 04:50
  • if you want a radical measure, exit AS, delete your $HOME\.gradle directory, delete C:\Users\project_path\app\.externalNativeBuild and C:\Users\project_path\.gradle and C:\Users\project_path.idea and all .iml files under C:\Users\project_path. Now, reopen the project. – Alex Cohn Nov 18 '17 at 05:46