Friendiqa/source-android/androidnative.pri/examples/androidnativeexample/android-sources/androidnative.gradle
2017-11-08 21:15:07 +01:00

35 lines
1.1 KiB
Groovy

// Obtain androidPackageSourceDir
// androidPackageSourceDir is the absolute path of the folder containing build.gradle and AndroidManifests.xml
// This code also works with androiddeployqt.
import groovy.json.JsonSlurper
String getAndroidPackageSourceDir() {
String res = System.getProperty("user.dir");
FileTree tree = fileTree(dir: res + "/..").include("android*deployment-settings.json");
if (tree.getFiles().size() > 0) {
def inputFile = tree.getFiles().toArray()[0];
def InputJSON = new JsonSlurper().parseText(inputFile.text);
res = InputJSON["android-package-source-directory"]
} else {
println("android*deployment-settings.json not found. Set androidPackageSourceDir to user.dir");
}
return res;
}
String setAndroidNativePath(String path) {
String androidPackageSourceDir = getAndroidPackageSourceDir();
String androidNativePath = androidPackageSourceDir + path + "/java/src";
LinkedHashSet hash = android.sourceSets.main.java.srcDirs;
hash.add(androidNativePath);
android.sourceSets.main.java.srcDirs = hash;
}
ext {
setAndroidNativePath = this.&setAndroidNativePath;
}