|
|
@@ -10,6 +10,9 @@ import org.codehaus.groovy.ast.stmt.Statement
|
|
|
import org.codehaus.groovy.control.SourceUnit
|
|
|
import org.codehaus.groovy.ast.builder.AstBuilder
|
|
|
import org.codehaus.groovy.ast.expr.ConstantExpression
|
|
|
+import com.google.gson.Gson
|
|
|
+import java.nio.file.Files
|
|
|
+import java.nio.file.Paths
|
|
|
|
|
|
|
|
|
class ModuleGradleVisitor : ClassCodeVisitorSupport() {
|
|
|
@@ -89,7 +92,10 @@ class ModuleGradleVisitor : ClassCodeVisitorSupport() {
|
|
|
|
|
|
val externalNativeBuild = findExternalNativeBuild(defaultConfigClosure)
|
|
|
if (externalNativeBuild == null) {
|
|
|
- (defaultConfigClosure.code as BlockStatement).statements.add(0, createExternalNativeBuildExpression())
|
|
|
+ (defaultConfigClosure.code as BlockStatement).statements.add(
|
|
|
+ 0,
|
|
|
+ createExternalNativeBuildExpression()
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -121,7 +127,7 @@ class ModuleGradleVisitor : ClassCodeVisitorSupport() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun findExternalNativeBuild(closure: ClosureExpression) : ArgumentListExpression? {
|
|
|
+ private fun findExternalNativeBuild(closure: ClosureExpression): ArgumentListExpression? {
|
|
|
val statements = (closure.code as BlockStatement).statements
|
|
|
|
|
|
for (statement in statements) {
|
|
|
@@ -136,20 +142,32 @@ class ModuleGradleVisitor : ClassCodeVisitorSupport() {
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
+ val jsonStr = String(Files.readAllBytes(Paths.get("src/main/resources/config.json")))
|
|
|
+
|
|
|
+ data class Config(
|
|
|
+ val minSdkVersion: String,
|
|
|
+ val ndkVersion: String,
|
|
|
+ val ndkPath: String
|
|
|
+ )
|
|
|
+
|
|
|
+ val cfg = Gson().fromJson(jsonStr, Config::class.java)
|
|
|
+
|
|
|
private fun createNdkPathExpression(): ExpressionStatement {
|
|
|
- val mavenNdkPathCode = "ndkPath '/opt/android-ndk-r23c'"
|
|
|
+ val jsonStr = Files.readAllBytes(Paths.get("src/main/resource/config.json"))
|
|
|
+
|
|
|
+ val mavenNdkPathCode = "ndkPath '${cfg.ndkPath}'"
|
|
|
val mavenNdkPathAst = AstBuilder().buildFromString(mavenNdkPathCode)
|
|
|
return ExpressionStatement(((mavenNdkPathAst[0] as BlockStatement).statements[0] as ReturnStatement).expression as MethodCallExpression)
|
|
|
}
|
|
|
|
|
|
private fun createMinSdkVersionExpression(): ExpressionStatement {
|
|
|
- val mavenMinSdkVersionCode = "minSdkVersion 29"
|
|
|
+ val mavenMinSdkVersionCode = "minSdkVersion ${cfg.minSdkVersion}"
|
|
|
val mavenMinSdkVersionAst = AstBuilder().buildFromString(mavenMinSdkVersionCode)
|
|
|
return ExpressionStatement(((mavenMinSdkVersionAst[0] as BlockStatement).statements[0] as ReturnStatement).expression as MethodCallExpression)
|
|
|
}
|
|
|
|
|
|
private fun createNdkVersionExpression(): ExpressionStatement {
|
|
|
- val mavenNdkVersionCode = "ndkVersion '23.2.0'"
|
|
|
+ val mavenNdkVersionCode = "ndkVersion '${cfg.ndkVersion}'"
|
|
|
val mavenNdkVersionAst = AstBuilder().buildFromString(mavenNdkVersionCode)
|
|
|
return ExpressionStatement(((mavenNdkVersionAst[0] as BlockStatement).statements[0] as ReturnStatement).expression as MethodCallExpression)
|
|
|
}
|