Skip to content

Commit

Permalink
Android: add Android Studio support, completely redone java part (#9066)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim committed Apr 15, 2020
1 parent 8ae8c16 commit 62ae7ad
Show file tree
Hide file tree
Showing 50 changed files with 1,129 additions and 2,520 deletions.
20 changes: 1 addition & 19 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@
*.swp
*.bak*
*.orig
.DS_Store
# Vim
*.vim
# Kate
Expand Down Expand Up @@ -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
Expand All @@ -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
11 changes: 11 additions & 0 deletions build/android/.gitignore
@@ -0,0 +1,11 @@
*.iml
.externalNativeBuild
.gradle
app/build
app/release
app/src/main/assets
build
local.properties
native/.*
native/build
native/deps
763 changes: 0 additions & 763 deletions build/android/Makefile

This file was deleted.

108 changes: 108 additions & 0 deletions build/android/app/build.gradle
@@ -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'
}
Expand Up @@ -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.