Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Android SDK directory within a gradle task

Recently the gradle plugin for android got updated (with android studio), after which the previous way of getting to the SDK directory ceased to work. The expression

${android.plugin.sdkDirectory}

which worked in an older version now returns the error

Error:(42, 0) No such property: sdkDirectory for class: com.android.build.gradle.LibraryPlugin

What would be the proper way of getting the android SDK directory being used, preferably independent of the user's configuration such as plugin and gradle version? The script needs to be shareable with several users.

like image 749
Combuster Avatar asked Jan 21 '26 10:01

Combuster


2 Answers

Since all the previous answers depend on the environment or specific user intervention on top of normal configuration, I'll just post my technically messy fix.

if (android.hasProperty('plugin')) {
    if (android.plugin.hasProperty('sdkHandler')) {
        androidPath = android.plugin.sdkHandler.sdkFolder
    } else {
        androidPath = android.plugin.sdkDirectory
    }
} else {
    androidPath = android.sdkDirectory
}

Unlike all previous methods, this actually works, but it still looks hacky.

like image 127
Combuster Avatar answered Jan 24 '26 02:01

Combuster


In gradle.properties set location sdkdir=/home/user/android-sdk and then in gradle you can use $sdkdir

like image 32
sujithvm Avatar answered Jan 24 '26 02:01

sujithvm