Browse Source

Make Android build smarter (SCons + Gradle)
Upgrade Gradle and Android plugin for Gradle
Disable all signing and zip-aligning for the export templates
Give correct names to generated APKs
Put .so files built by SCons right where Gradle has to pick them according to arch & build type
Downgrade NDK platform to 14 to match minSdkVersion

Pedro J. Estébanez 9 years ago
parent
commit
e7b2626707

+ 1 - 8
.gitignore

@@ -37,17 +37,10 @@ platform/android/java/.gradle
 platform/android/java/.gradletasknamecache
 platform/android/java/.gradletasknamecache
 platform/android/java/local.properties
 platform/android/java/local.properties
 platform/android/java/project.properties
 platform/android/java/project.properties
+platform/android/java/build.gradle
 platform/android/java/AndroidManifest.xml
 platform/android/java/AndroidManifest.xml
-platform/android/java/bin/*
 platform/android/java/libs/*
 platform/android/java/libs/*
-platform/android/java/gen/*
 platform/android/java/assets
 platform/android/java/assets
-platform/android/libs/apk_expansion/bin/*
-platform/android/libs/apk_expansion/gen/*
-platform/android/libs/google_play_services/bin/*
-platform/android/libs/google_play_services/gen/*
-platform/android/libs/play_licensing/bin/*
-platform/android/libs/play_licensing/gen/*
 
 
 # General c++ generated files
 # General c++ generated files
 *.lib
 *.lib

+ 19 - 1
platform/android/SCsub

@@ -103,4 +103,22 @@ pp_baseout.write( manifest )
 
 
 env_android.SharedLibrary("#bin/libgodot",[android_objects],SHLIBSUFFIX=env["SHLIBSUFFIX"])
 env_android.SharedLibrary("#bin/libgodot",[android_objects],SHLIBSUFFIX=env["SHLIBSUFFIX"])
 
 
-#env.Command('#bin/libgodot_android.so', '#platform/android/libgodot_android.so', Copy('bin/libgodot_android.so', 'platform/android/libgodot_android.so'))
+
+lib_arch_dir = ''
+if env['android_arch'] == 'armv6':
+	lib_arch_dir = 'armeabi'
+elif env['android_arch'] == 'armv7':
+	lib_arch_dir = 'armeabi-v7a'
+elif env['android_arch'] == 'x86':
+	lib_arch_dir = 'x86'
+else:
+	print 'WARN: Architecture not suitable for embedding into APK; keeping .so at \\bin'
+
+if lib_arch_dir != '':
+	if env['target'] == 'release':
+		lib_type_dir = 'release'
+	else: # release_debug, debug
+		lib_type_dir = 'debug'
+		
+	out_dir = '#platform/android/java/libs/'+lib_type_dir+'/'+lib_arch_dir
+	env_android.Command(out_dir+'/libgodot_android.so', '#bin/libgodot'+env['SHLIBSUFFIX'], Move("$TARGET", "$SOURCE"))

+ 18 - 4
platform/android/build.gradle.template

@@ -3,7 +3,7 @@ buildscript {
 		jcenter()
 		jcenter()
 	}
 	}
 	dependencies {
 	dependencies {
-		classpath 'com.android.tools.build:gradle:1.3.1'
+		classpath 'com.android.tools.build:gradle:2.1.0'
 	}
 	}
 }
 }
 
 
@@ -40,6 +40,11 @@ android {
 		minSdkVersion 14
 		minSdkVersion 14
 		targetSdkVersion 23
 		targetSdkVersion 23
 	}
 	}
+	// Both signing and zip-aligning will be done at export time
+	buildTypes.all { buildType ->
+		buildType.zipAlignEnabled false
+		buildType.signingConfig null
+	}
 	sourceSets {
 	sourceSets {
 		main {
 		main {
 			manifest.srcFile 'AndroidManifest.xml'
 			manifest.srcFile 'AndroidManifest.xml'
@@ -65,8 +70,17 @@ android {
 				$$GRADLE_JNI_DIRS$$
 				$$GRADLE_JNI_DIRS$$
 			]
 			]
 		}
 		}
-
+		debug.jniLibs.srcDirs = [
+			'libs/debug'
+			$$GRADLE_JNI_DIRS$$
+		]
+		release.jniLibs.srcDirs = [
+			'libs/release'
+			$$GRADLE_JNI_DIRS$$
+		]
+	}
+	applicationVariants.all { variant ->
+		// ApplicationVariant is undocumented, but this method is widely used; may break with another version of the Android Gradle plugin
+		variant.outputs.get(0).setOutputFile(new File("${projectDir}/../../../bin", "android_${variant.name}.apk"))
 	}
 	}
-
-
 }
 }

+ 1 - 1
platform/android/detect.py

@@ -23,7 +23,7 @@ def get_opts():
 			('ANDROID_NDK_ROOT', 'the path to Android NDK', os.environ.get("ANDROID_NDK_ROOT", 0)),
 			('ANDROID_NDK_ROOT', 'the path to Android NDK', os.environ.get("ANDROID_NDK_ROOT", 0)),
 			('NDK_TARGET', 'toolchain to use for the NDK',os.environ.get("NDK_TARGET", "arm-linux-androideabi-4.9")),
 			('NDK_TARGET', 'toolchain to use for the NDK',os.environ.get("NDK_TARGET", "arm-linux-androideabi-4.9")),
 			('NDK_TARGET_X86', 'toolchain to use for the NDK x86',os.environ.get("NDK_TARGET_X86", "x86-4.9")),
 			('NDK_TARGET_X86', 'toolchain to use for the NDK x86',os.environ.get("NDK_TARGET_X86", "x86-4.9")),
-			('ndk_platform', 'compile for platform: (android-<api> , example: android-15)',"android-15"),
+			('ndk_platform', 'compile for platform: (android-<api> , example: android-14)',"android-14"),
 			('android_arch', 'select compiler architecture: (armv7/armv6/x86)',"armv7"),
 			('android_arch', 'select compiler architecture: (armv7/armv6/x86)',"armv7"),
 			('android_neon','enable neon (armv7 only)',"yes"),
 			('android_neon','enable neon (armv7 only)',"yes"),
 			('android_stl','enable STL support in android port (for modules)',"no")
 			('android_stl','enable STL support in android port (for modules)',"no")

+ 1 - 1
platform/android/export/export.cpp

@@ -1166,7 +1166,7 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d
 			skip=true;
 			skip=true;
 		}
 		}
 
 
-		if (file=="lib/armeabi/libgodot_android.so" && !export_arm) {
+		if (file.match("lib/armeabi*/libgodot_android.so") && !export_arm) {
 			skip=true;
 			skip=true;
 		}
 		}
 
 

+ 1 - 1
platform/android/java/gradle/wrapper/gradle-wrapper.properties

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip