1

In my build.gradle file in Android Studio using NDK, I have the following code. The app builds if I run it from the terminal with "./gradlew --assembleDebug" since I have set the path for ANDROID_NDK_HOME to /Users/chenige/Desktop/android-ndk-r9, but it will not build from inside Android Studio. From inside Android Studio, System.env.ANDROID_NDK_HOME is "null". Does anybody know why/how I can fix this?

    task buildNative(type: Exec) {
    if (System.env.ANDROID_NDK_HOME != null) {
        def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
        commandLine ndkBuild

    } else {
        doLast {
            println '##################'
            println 'Skipping NDK build'
            println 'Reason: ANDROID_NDK_HOME not set.'
            println '##################'
        }
    }
}

}

iamcamcamiam2
  • 75
  • 2
  • 7

2 Answers2

0

Android Studio doesn't read environment variables, so this approach won't work. Also, using the projectDir scheme in settings.gradle will probably cause problems. Android Studio has a limitation that all of its modules need to be located underneath the project root. If you have libraries that are used in multiple projects and they can't be placed under a single project root, the best advice is to have them publish JARs or AARs to a local Maven repository that individual projects can pick up.

read more Environment variable in settings.gradle not working with Android Studio

Community
  • 1
  • 1
kablu
  • 629
  • 1
  • 7
  • 26
0

It works for me with the follwoing steps:

  1. Set your variable in Windows
  2. Reboot
  3. reach it in gradle build: "$System.env.MYVARIABLE"
narancs
  • 5,234
  • 4
  • 41
  • 60