Split the Android platform java logic into an Android library module (lib) and an application module (app).

The application module `app` serves double duties of providing the prebuilt Godot binaries ('android_debug.apk', 'android_release.apk') and the Godot custom build template ('android_source.zip').
This commit is contained in:
fhuya
2019-09-02 17:31:51 -07:00
parent ba854bbc7b
commit 7fabfd402f
141 changed files with 386 additions and 282 deletions

View File

@@ -41,7 +41,7 @@
android:value="xr_mode_metadata_value" />
<activity
android:name="org.godotengine.godot.Godot"
android:name=".GodotApp"
android:label="@string/godot_project_name_string"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
@@ -56,18 +56,10 @@
</intent-filter>
</activity>
<service android:name="org.godotengine.godot.GodotDownloaderService" />
<!-- Custom application XML added by add-ons. -->
<!--CHUNK_APPLICATION_BEGIN-->
<!--CHUNK_APPLICATION_END-->
</application>
<instrumentation
android:icon="@drawable/icon"
android:label="@string/godot_project_name_string"
android:name="org.godotengine.godot.GodotInstrumentation"
android:targetPackage="org.godotengine.game" />
</manifest>

View File

@@ -0,0 +1,121 @@
// Gradle build config for Godot Engine's Android port.
//
// Do not remove/modify comments ending with BEGIN/END, they are used to inject
// addon-specific configuration.
apply from: 'config.gradle'
buildscript {
apply from: 'config.gradle'
repositories {
google()
jcenter()
//CHUNK_BUILDSCRIPT_REPOSITORIES_BEGIN
//CHUNK_BUILDSCRIPT_REPOSITORIES_END
}
dependencies {
classpath libraries.androidGradlePlugin
//CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN
//CHUNK_BUILDSCRIPT_DEPENDENCIES_END
}
}
apply plugin: 'com.android.application'
allprojects {
repositories {
mavenCentral()
google()
jcenter()
//CHUNK_ALLPROJECTS_REPOSITORIES_BEGIN
//CHUNK_ALLPROJECTS_REPOSITORIES_END
}
}
dependencies {
if (rootProject.findProject(":lib")) {
implementation project(":lib")
} else {
// Custom build mode. In this scenario this project is the only one around and the Godot
// library is available through the pre-generated godot-lib.*.aar android archive files.
debugImplementation fileTree(dir: 'libs/debug', include: ['*.jar', '*.aar'])
releaseImplementation fileTree(dir: 'libs/release', include: ['*.jar', '*.aar'])
}
//CHUNK_DEPENDENCIES_BEGIN
//CHUNK_DEPENDENCIES_END
}
android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
defaultConfig {
// Feel free to modify the application id to your own.
applicationId "com.godot.game"
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
//CHUNK_ANDROID_DEFAULTCONFIG_BEGIN
//CHUNK_ANDROID_DEFAULTCONFIG_END
}
lintOptions {
abortOnError false
disable 'MissingTranslation', 'UnusedResources'
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
// Both signing and zip-aligning will be done at export time
buildTypes.all { buildType ->
buildType.zipAlignEnabled false
buildType.signingConfig null
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [
'src'
//DIR_SRC_BEGIN
//DIR_SRC_END
]
res.srcDirs = [
'res'
//DIR_RES_BEGIN
//DIR_RES_END
]
aidl.srcDirs = [
'aidl'
//DIR_AIDL_BEGIN
//DIR_AIDL_END
]
assets.srcDirs = [
'assets'
//DIR_ASSETS_BEGIN
//DIR_ASSETS_END
]
}
debug.jniLibs.srcDirs = [
'libs/debug'
//DIR_JNI_DEBUG_BEGIN
//DIR_JNI_DEBUG_END
]
release.jniLibs.srcDirs = [
'libs/release'
//DIR_JNI_RELEASE_BEGIN
//DIR_JNI_RELEASE_END
]
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
output.outputFileName = "android_${variant.name}.apk"
}
}
}
//CHUNK_GLOBAL_BEGIN
//CHUNK_GLOBAL_END

View File

@@ -0,0 +1,12 @@
ext.versions = [
androidGradlePlugin : '3.4.2',
compileSdk : 28,
minSdk : 18,
targetSdk : 28,
buildTools : '28.0.3',
]
ext.libraries = [
androidGradlePlugin : "com.android.tools.build:gradle:$versions.androidGradlePlugin"
]

View File

@@ -0,0 +1,10 @@
package com.godot.game;
import org.godotengine.godot.Godot;
/**
* Template activity for Godot Android custom builds.
* Feel free to extend and modify this class for your custom logic.
*/
public class GodotApp extends Godot {
}

View File

@@ -1,111 +1,95 @@
// Gradle build config for Godot Engine's Android port.
//
// Do not remove/modify comments ending with BEGIN/END, they are used to inject
// addon-specific configuration.
apply from: 'app/config.gradle'
buildscript {
apply from: 'app/config.gradle'
repositories {
google()
jcenter()
//CHUNK_BUILDSCRIPT_REPOSITORIES_BEGIN
//CHUNK_BUILDSCRIPT_REPOSITORIES_END
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
//CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN
//CHUNK_BUILDSCRIPT_DEPENDENCIES_END
classpath libraries.androidGradlePlugin
}
}
apply plugin: 'com.android.application'
allprojects {
repositories {
mavenCentral()
google()
jcenter()
//CHUNK_ALLPROJECTS_REPOSITORIES_BEGIN
//CHUNK_ALLPROJECTS_REPOSITORIES_END
mavenCentral()
}
}
dependencies {
implementation "com.android.support:support-core-utils:28.0.0"
//CHUNK_DEPENDENCIES_BEGIN
//CHUNK_DEPENDENCIES_END
def binDir = "../../../bin/"
/**
* Copy the generated 'android_debug.apk' binary template into the Godot bin directory.
* Depends on the app build task to ensure the binary is generated prior to copying.
*/
task copyDebugBinaryToBin(type: Copy) {
dependsOn ':app:build'
from('app/build/outputs/apk/debug')
into(binDir)
include('android_debug.apk')
}
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
//CHUNK_ANDROID_DEFAULTCONFIG_BEGIN
//CHUNK_ANDROID_DEFAULTCONFIG_END
}
lintOptions {
abortOnError false
disable 'MissingTranslation', 'UnusedResources'
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
// Both signing and zip-aligning will be done at export time
buildTypes.all { buildType ->
buildType.zipAlignEnabled false
buildType.signingConfig null
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [
'src'
//DIR_SRC_BEGIN
//DIR_SRC_END
]
res.srcDirs = [
'res'
//DIR_RES_BEGIN
//DIR_RES_END
]
aidl.srcDirs = [
'aidl'
//DIR_AIDL_BEGIN
//DIR_AIDL_END
]
assets.srcDirs = [
'assets'
//DIR_ASSETS_BEGIN
//DIR_ASSETS_END
]
}
debug.jniLibs.srcDirs = [
'libs/debug'
//DIR_JNI_DEBUG_BEGIN
//DIR_JNI_DEBUG_END
]
release.jniLibs.srcDirs = [
'libs/release'
//DIR_JNI_RELEASE_BEGIN
//DIR_JNI_RELEASE_END
]
}
// No longer used, as it's not useful for build source template
//applicationVariants.all { variant ->
// variant.outputs.all { output ->
// output.outputFileName = "../../../../../../../bin/android_${variant.name}.apk"
// }
//}
/**
* Copy the generated 'android_release.apk' binary template into the Godot bin directory.
* Depends on the app build task to ensure the binary is generated prior to copying.
*/
task copyReleaseBinaryToBin(type: Copy) {
dependsOn ':app:build'
from('app/build/outputs/apk/release')
into(binDir)
include('android_release.apk')
}
//CHUNK_GLOBAL_BEGIN
//CHUNK_GLOBAL_END
/**
* Copy the Godot android library archive debug file into the app debug libs directory.
* Depends on the library build task to ensure the AAR file is generated prior to copying.
*/
task copyDebugAAR(type: Copy) {
dependsOn ':lib:build'
from('lib/build/outputs/aar')
into('app/libs/debug')
include('godot-lib.debug.aar')
}
/**
* Copy the Godot android library archive release file into the app release libs directory.
* Depends on the library build task to ensure the AAR file is generated prior to copying.
*/
task copyReleaseAAR(type: Copy) {
dependsOn ':lib:build'
from('lib/build/outputs/aar')
into('app/libs/release')
include('godot-lib.release.aar')
}
/**
* Generate Godot custom build template by zipping the source files from the app directory, as well
* as the AAR files generated by 'copyDebugAAR' and 'copyReleaseAAR'.
* The zip file also includes some gradle tools to allow building of the custom build.
*/
task zipCustomBuild(type: Zip) {
dependsOn 'copyDebugAAR'
dependsOn 'copyReleaseAAR'
from(fileTree(dir: 'app', excludes: ['**/build/**', '**/.gradle/**', '**/*.iml']), fileTree(dir: '.', includes: ['gradle.properties','gradlew', 'gradlew.bat', 'gradle/**']))
include '**/*'
archiveName 'android_source.zip'
destinationDir(file(binDir))
}
/**
* Master task used to coordinate the tasks defined above to generate the set of Godot templates.
*/
task generateGodotTemplates(type: GradleBuild) {
tasks = [
// Copy the generated aar library files to the custom build directory.
'copyDebugAAR', 'copyReleaseAAR',
// Zip the custom build directory.
'zipCustomBuild',
// Copy the prebuilt binary templates to the bin directory.
'copyDebugBinaryToBin', 'copyReleaseBinaryToBin',
]
}

View File

@@ -1,5 +1,6 @@
#Mon Sep 02 02:44:30 PDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.godotengine.godot"
android:versionCode="1"
android:versionName="1.0">
<application>
<service android:name=".GodotDownloaderService" />
</application>
<instrumentation
android:icon="@drawable/icon"
android:label="@string/godot_project_name_string"
android:name=".GodotInstrumentation"
android:targetPackage="org.godotengine.godot" />
</manifest>

View File

@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.6)
project(godot)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(GODOT_ROOT_DIR ../../../..)
# Get sources
file(GLOB_RECURSE SOURCES ${GODOT_ROOT_DIR}/*.c**)
file(GLOB_RECURSE HEADERS ${GODOT_ROOT_DIR}/*.h**)
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME}
SYSTEM PUBLIC
${GODOT_ROOT_DIR}
${GODOT_ROOT_DIR}/modules/gdnative/include)

View File

@@ -0,0 +1,91 @@
apply plugin: 'com.android.library'
dependencies {
implementation "com.android.support:support-core-utils:28.0.0"
}
def pathToRootDir = "../../../../"
// Note: Only keep the abis you support to speed up the gradle 'assemble' task.
def supportedAbis = ["armv7", "arm64v8", "x86", "x86_64"]
android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
}
lintOptions {
abortOnError false
disable 'MissingTranslation', 'UnusedResources'
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['aidl']
assets.srcDirs = ['assets']
}
debug.jniLibs.srcDirs = ['libs/debug']
release.jniLibs.srcDirs = ['libs/release']
}
libraryVariants.all { variant ->
variant.outputs.all { output ->
output.outputFileName = "godot-lib.${variant.name}.aar"
}
def buildType = variant.buildType.name.capitalize()
def taskPrefix = ""
if (project.path != ":") {
taskPrefix = project.path + ":"
}
// Disable the externalNativeBuild* task as it would cause build failures since the cmake build
// files is only setup for editing support.
gradle.startParameter.excludedTaskNames += taskPrefix + "externalNativeBuild" + buildType
// Create tasks to generate the Godot native libraries.
def taskName = "compileGodotNativeLibs" + buildType
def releaseTarget = "release"
if (buildType == "Debug") {
releaseTarget += "_debug"
}
def abiTaskNames = []
// Creating gradle tasks to generate the native libraries for the supported abis.
supportedAbis.each { abi ->
def abiTaskName = taskName + abi.capitalize()
abiTaskNames += abiTaskName
tasks.create(name: abiTaskName, type: Exec) {
executable "scons"
args "--directory=${pathToRootDir}", "platform=android", "target=${releaseTarget}", "android_arch=${abi}"
}
}
// Creating gradle task to run all of the previously generated tasks.
tasks.create(name: taskName, type: GradleBuild) {
tasks = abiTaskNames
}
// Schedule the tasks so the generated libs are present before the aar file is packaged.
tasks["merge${buildType}JniLibFolders"].dependsOn taskName
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}

View File

@@ -175,7 +175,7 @@ index e4b1b0f1c..36cd6aacf 100644
-import com.android.vending.expansion.downloader.R;
+// -- GODOT start --
+//import com.android.vending.expansion.downloader.R;
+import com.godot.game.R;
+import org.godotengine.godot.R;
+// -- GODOT end --
import java.io.File;
@@ -250,7 +250,7 @@ index f1536e80e..4b214b22d 100644
-import com.android.vending.expansion.downloader.R;
+// -- GODOT start --
+//import com.android.vending.expansion.downloader.R;
+import com.godot.game.R;
+import org.godotengine.godot.R;
+// -- GODOT end --
+
import com.google.android.vending.expansion.downloader.DownloadProgressInfo;

View File

@@ -21,7 +21,7 @@ index a0d2779af..a8bf65f9c 100644
*/
+// -- GODOT start --
+import com.godot.game.BuildConfig;
import org.godotengine.godot.BuildConfig;
+// -- GODOT end --
+
/**

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -26,7 +26,7 @@ import android.util.Log;
// -- GODOT start --
//import com.android.vending.expansion.downloader.R;
import com.godot.game.R;
import org.godotengine.godot.R;
// -- GODOT end --
import java.io.File;

View File

@@ -18,7 +18,7 @@ package com.google.android.vending.expansion.downloader.impl;
// -- GODOT start --
//import com.android.vending.expansion.downloader.R;
import com.godot.game.R;
import org.godotengine.godot.R;
// -- GODOT end --
import com.google.android.vending.expansion.downloader.DownloadProgressInfo;

View File

@@ -32,7 +32,7 @@ package com.google.android.vending.licensing.util;
*/
// -- GODOT start --
import com.godot.game.BuildConfig;
import org.godotengine.godot.BuildConfig;
// -- GODOT end --
/**

View File

@@ -97,7 +97,7 @@ import org.godotengine.godot.input.GodotEditText;
import org.godotengine.godot.payments.PaymentsManager;
import org.godotengine.godot.xr.XRMode;
public class Godot extends Activity implements SensorEventListener, IDownloaderClient {
public abstract class Godot extends Activity implements SensorEventListener, IDownloaderClient {
static final int MAX_SINGLETONS = 64;
static final int REQUEST_RECORD_AUDIO_PERMISSION = 1;
@@ -146,8 +146,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
private void setButtonPausedState(boolean paused) {
mStatePaused = paused;
int stringResourceID = paused ? com.godot.game.R.string.text_button_resume :
com.godot.game.R.string.text_button_pause;
int stringResourceID = paused ? R.string.text_button_resume :
R.string.text_button_pause;
mPauseButton.setText(stringResourceID);
}
@@ -357,7 +357,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
//
Bundle args = new Bundle();
args.putParcelable("intent", mCurrentIntent);
startInstrumentation(new ComponentName(Godot.this, GodotInstrumentation.class), null, args);
startInstrumentation(new ComponentName(this, GodotInstrumentation.class), null, args);
}
public void alert(final String message, final String title) {
@@ -614,17 +614,17 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,
GodotDownloaderService.class);
setContentView(com.godot.game.R.layout.downloading_expansion);
mPB = (ProgressBar)findViewById(com.godot.game.R.id.progressBar);
mStatusText = (TextView)findViewById(com.godot.game.R.id.statusText);
mProgressFraction = (TextView)findViewById(com.godot.game.R.id.progressAsFraction);
mProgressPercent = (TextView)findViewById(com.godot.game.R.id.progressAsPercentage);
mAverageSpeed = (TextView)findViewById(com.godot.game.R.id.progressAverageSpeed);
mTimeRemaining = (TextView)findViewById(com.godot.game.R.id.progressTimeRemaining);
mDashboard = findViewById(com.godot.game.R.id.downloaderDashboard);
mCellMessage = findViewById(com.godot.game.R.id.approveCellular);
mPauseButton = (Button)findViewById(com.godot.game.R.id.pauseButton);
mWiFiSettingsButton = (Button)findViewById(com.godot.game.R.id.wifiSettingsButton);
setContentView(R.layout.downloading_expansion);
mPB = (ProgressBar)findViewById(R.id.progressBar);
mStatusText = (TextView)findViewById(R.id.statusText);
mProgressFraction = (TextView)findViewById(R.id.progressAsFraction);
mProgressPercent = (TextView)findViewById(R.id.progressAsPercentage);
mAverageSpeed = (TextView)findViewById(R.id.progressAverageSpeed);
mTimeRemaining = (TextView)findViewById(R.id.progressTimeRemaining);
mDashboard = findViewById(R.id.downloaderDashboard);
mCellMessage = findViewById(R.id.approveCellular);
mPauseButton = (Button)findViewById(R.id.pauseButton);
mWiFiSettingsButton = (Button)findViewById(R.id.wifiSettingsButton);
return;
}
@@ -1094,9 +1094,9 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
mAverageSpeed.setText(getString(com.godot.game.R.string.kilobytes_per_second,
mAverageSpeed.setText(getString(R.string.kilobytes_per_second,
Helpers.getSpeedString(progress.mCurrentSpeed)));
mTimeRemaining.setText(getString(com.godot.game.R.string.time_remaining,
mTimeRemaining.setText(getString(R.string.time_remaining,
Helpers.getTimeRemaining(progress.mTimeRemaining)));
mPB.setMax((int)(progress.mOverallTotal >> 8));

Some files were not shown because too many files have changed in this diff Show More