Skip to content
Permalink
Browse files

Android: add Android Studio support, completely redone java part (#9066)

  • Loading branch information
MoNTE48 committed Apr 15, 2020
1 parent 8ae8c16 commit 62ae7adab2bebde04864c12543caefbffab24963
Showing with 1,129 additions and 2,520 deletions.
  1. +1 −19 .gitignore
  2. +11 −0 build/android/.gitignore
  3. +0 −763 build/android/Makefile
  4. +108 −0 build/android/app/build.gradle
  5. +19 −19 build/android/{ → app}/src/main/AndroidManifest.xml
  6. +82 −0 build/android/app/src/main/java/net/minetest/minetest/CopyZipTask.java
  7. +58 −46 ...etest.minetest/MtNativeActivity.java → app/src/main/java/net/minetest/minetest/GameActivity.java}
  8. +98 −0 build/android/app/src/main/java/net/minetest/minetest/InputDialogActivity.java
  9. +139 −0 build/android/app/src/main/java/net/minetest/minetest/MainActivity.java
  10. +153 −0 build/android/app/src/main/java/net/minetest/minetest/UnzipService.java
  11. BIN build/android/{ → app}/src/main/res/drawable/background.png
  12. +1 −1 build/android/{ → app}/src/main/res/drawable/bg.xml
  13. +30 −0 build/android/app/src/main/res/layout/activity_main.xml
  14. BIN build/android/{ → app}/src/main/res/mipmap/ic_launcher.png
  15. +10 −0 build/android/app/src/main/res/values/strings.xml
  16. +22 −0 build/android/app/src/main/res/values/styles.xml
  17. +17 −158 build/android/build.gradle
  18. +10 −1 build/android/gradle.properties
  19. BIN build/android/gradle/wrapper/gradle-wrapper.jar
  20. +2 −1 build/android/gradle/wrapper/gradle-wrapper.properties
  21. +19 −3 build/android/gradlew
  22. +17 −1 build/android/gradlew.bat
  23. +0 −448 build/android/jni/Android.mk
  24. +0 −9 build/android/jni/Application.mk
  25. +0 −7 build/android/jni/Deps.mk
  26. +0 −8 build/android/jni/Irrlicht.mk
  27. +59 −0 build/android/native/build.gradle
  28. +218 −0 build/android/native/jni/Android.mk
  29. +32 −0 build/android/native/jni/Application.mk
  30. +1 −0 build/android/native/src/main/AndroidManifest.xml
  31. +0 −20 build/android/patches/irrlicht-back_button.patch
  32. +0 −13 build/android/patches/irrlicht-native_activity.patch
  33. +0 −240 build/android/patches/irrlicht-texturehack.patch
  34. +0 −30 build/android/patches/irrlicht-touchcount.patch
  35. +0 −37 build/android/patches/libvorbis-libogg-fpu.patch
  36. +0 −13 build/android/patches/openssl_arch.patch
  37. +1 −0 build/android/settings.gradle
  38. +0 −77 build/android/src/main/java/net.minetest.minetest/MainActivity.java
  39. +0 −371 build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java
  40. +0 −87 build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java
  41. +0 −24 build/android/src/main/res/layout/assetcopy.xml
  42. +0 −17 build/android/src/main/res/values-v21/styles.xml
  43. +0 −5 build/android/src/main/res/values/strings.xml
  44. +0 −14 build/android/src/main/res/values/styles.xml
  45. +14 −61 doc/README.android
  46. +3 −3 src/config.h
  47. +0 −1 src/main.cpp
  48. +3 −14 src/porting_android.cpp
  49. +0 −5 src/porting_android.h
  50. +1 −4 src/version.cpp
@@ -3,6 +3,7 @@
*.swp
*.bak*
*.orig
.DS_Store
# Vim
*.vim
# Kate
@@ -77,17 +78,11 @@ doc/mkdocs/mkdocs.yml
## Build files
CMakeFiles
Makefile
!build/android/Makefile
build/android/path.cfg
build/android/*.apk
build/android/.externalNativeBuild
cmake_install.cmake
CMakeCache.txt
CPackConfig.cmake
CPackSourceConfig.cmake
src/test_config.h
src/android_version.h
src/android_version_githash.h
src/cmake_config.h
src/cmake_config_githash.h
src/unittest/test_world/world.mt
@@ -109,16 +104,3 @@ cmake_config.h
cmake_config_githash.h
CMakeDoxy*
compile_commands.json

## Android build files
build/android/src/main/assets
build/android/build
build/android/deps
build/android/libs
build/android/jni/lib
build/android/jni/src
build/android/src/main/jniLibs
build/android/obj
build/android/local.properties
build/android/.gradle
timestamp
@@ -0,0 +1,11 @@
*.iml
.externalNativeBuild
.gradle
app/build
app/release
app/src/main/assets
build
local.properties
native/.*
native/build
native/deps

This file was deleted.

@@ -0,0 +1,108 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion '29.0.3'
ndkVersion '21.0.6113669'
defaultConfig {
applicationId 'net.minetest.minetest'
minSdkVersion 16
//noinspection OldTargetApi
targetSdkVersion 28 // Workaround for using `/sdcard` instead of the `data` patch for assets
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
versionCode project.versionCode
}

Properties props = new Properties()
props.load(new FileInputStream(file('../local.properties')))

if (props.getProperty('keystore') != null) {
signingConfigs {
release {
storeFile file(props['keystore'])
storePassword props['keystore.password']
keyAlias props['key']
keyPassword props['key.password']
}
}

buildTypes {
release {
minifyEnabled true
signingConfig signingConfigs.release
}
}
}

// for multiple APKs
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

task prepareAssets() {
def assetsFolder = "build/assets"
def projRoot = "../../.."
def gameToCopy = "minetest_game"

copy {
from "${projRoot}/minetest.conf.example", "${projRoot}/README.md" into assetsFolder
}
copy {
from "${projRoot}/doc/lgpl-2.1.txt" into "${assetsFolder}"
rename("lgpl-2.1.txt", "LICENSE.txt")
}
copy {
from "${projRoot}/builtin" into "${assetsFolder}/builtin"
}
copy {
from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders"
}
copy {
from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts"
}
copy {
from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}"
}
/*copy {
// locales broken right now
// ToDo: fix it!
from "${projRoot}/po" into "${assetsFolder}/po"
}*/
copy {
from "${projRoot}/textures" into "${assetsFolder}/textures"
}

task zipAssets(type: Zip) {
archiveName "Minetest.zip"
from "${assetsFolder}"
destinationDir file("src/main/assets")
}
}

preBuild.dependsOn zipAssets

// Map for the version code that gives each ABI a value.
import com.android.build.OutputFile

def abiCodes = ['armeabi-v7a': 0, 'arm64-v8a': 1]
android.applicationVariants.all { variant ->
variant.outputs.each {
output ->
def abiName = output.getFilter(OutputFile.ABI)
output.versionCodeOverride = abiCodes.get(abiName, 0) + variant.versionCode
}
}

dependencies {
implementation project(':native')
implementation 'androidx.appcompat:appcompat:1.1.0'
}
@@ -4,57 +4,57 @@
package="net.minetest.minetest"
android:installLocation="auto">

<uses-feature
android:glEsVersion="0x00010000"
android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="${project}"
android:label="@string/label"
android:resizeableActivity="false"
tools:targetApi="n">
tools:ignore="UnusedAttribute">

<meta-data
android:name="android.max_aspect"
android:value="2.4" />
android:value="3" />

<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:label="${project}"
android:launchMode="singleTask"
android:maxAspectRatio="3"
android:screenOrientation="sensorLandscape"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MtNativeActivity"
android:name=".GameActivity"
android:configChanges="orientation|keyboard|keyboardHidden|navigation|screenSize|smallestScreenSize"
android:hardwareAccelerated="true"
android:launchMode="singleTask"
android:maxAspectRatio="3"
android:screenOrientation="sensorLandscape"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="minetest" />
android:value="Minetest" />
</activity>

<activity
android:name=".MinetestTextEntry"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/Theme.Dialog"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".MinetestAssetCopy"
android:screenOrientation="sensorLandscape"
android:theme="@style/AppTheme" />
android:name=".InputDialogActivity"
android:maxAspectRatio="3"
android:theme="@style/InputTheme" />

<service
android:name=".UnzipService"
android:enabled="true"
android:exported="false" />
</application>

</manifest>
@@ -0,0 +1,82 @@
/*
Minetest
Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik <MoNTE48@mail.ua>
Copyright (C) 2014-2020 ubulem, Bektur Mambetov <berkut87@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package net.minetest.minetest;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.util.Log;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;

public class CopyZipTask extends AsyncTask<String, Void, String> {

private final WeakReference<Context> contextRef;

CopyZipTask(Context context) {
contextRef = new WeakReference<>(context);
}

protected String doInBackground(String... params) {
copyAssets(params);
return params[0];
}

@Override
protected void onPostExecute(String result) {
startUnzipService(result);
}

private void copyAsset(String zipName) throws IOException {
String filename = zipName.substring(zipName.lastIndexOf("/") + 1);
try (InputStream in = contextRef.get().getAssets().open(filename);
OutputStream out = new FileOutputStream(zipName)) {
copyFile(in, out);
}
}

private void copyAssets(String[] zips) {
try {
for (String zipName : zips)
copyAsset(zipName);
} catch (IOException e) {
Log.e("CopyZipTask", e.getLocalizedMessage());
cancel(true);
}
}

private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1)
out.write(buffer, 0, read);
}

private void startUnzipService(String file) {
Intent intent = new Intent(contextRef.get(), UnzipService.class);
intent.putExtra(UnzipService.EXTRA_KEY_IN_FILE, file);
contextRef.get().startService(intent);
}
}

0 comments on commit 62ae7ad

Please sign in to comment.
You can’t perform that action at this time.