我正在编写自定义gradle插件。 在我的自定义插件中,如何获取主机项目的compileSdkVersion。
答案 0 :(得分:0)
您可以从project.android.compileSdkVersion
apply plugin: CompileSdkVersionPlugin
...
class CompileSdkVersionPlugin implements Plugin<Project> {
void apply(Project project) {
project.task('compileSdkVersion') {
doLast {
println project.android.compileSdkVersion
}
}
}
}
然后终端中的gradle -q compileSdkVersion
命令将打印此输出:
android-25
答案 1 :(得分:0)
此外,我们甚至可以获得android.jar路径的compilesdkversion。用Java代码
private static String getAndroidJarPath(Project project) {
AppExtension appExtension = (AppExtension)project.getProperties().get("android");
String sdkDirectory = appExtension.getSdkDirectory().getAbsolutePath();
String compileSdkVersion = appExtension.getCompileSdkVersion();
sdkDirectory = sdkDirectory + File.separator + "platforms" + File.separator
String androidJarPath = sdkDirectory + compileSdkVersion + File.separator + "android.jar";
return androidJarPath;
}