-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: add Android Studio support, completely redone java part (#9066)
- Loading branch information
Maksim
committed
Apr 15, 2020
1 parent
8ae8c16
commit 62ae7ad
Showing
50 changed files
with
1,129 additions
and
2,520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
build/android/app/src/main/java/net/minetest/minetest/CopyZipTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.