Partial 7.0 merge - API preview
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
android:usesCleartextTraffic="true"
|
||||
android:appCategory="game"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/ArcTheme" android:fullBackupContent="@xml/backup_rules">
|
||||
android:theme="@style/ArcTheme"
|
||||
android:fullBackupContent="@xml/backup_rules">
|
||||
<meta-data android:name="android.max_aspect" android:value="2.1"/>
|
||||
<activity
|
||||
android:name="mindustry.android.AndroidLauncher"
|
||||
|
||||
@@ -20,22 +20,7 @@ configurations{ natives }
|
||||
repositories{
|
||||
mavenCentral()
|
||||
maven{ url "https://maven.google.com" }
|
||||
jcenter() //remove later once google fixes the dependency
|
||||
}
|
||||
|
||||
dependencies{
|
||||
implementation project(":core")
|
||||
|
||||
implementation arcModule("backends:backend-android")
|
||||
implementation 'com.jakewharton.android.repackaged:dalvik-dx:9.0.0_r3'
|
||||
|
||||
natives "com.github.Anuken.Arc:natives-android:${getArcHash()}"
|
||||
natives "com.github.Anuken.Arc:natives-freetype-android:${getArcHash()}"
|
||||
natives "com.github.Anuken.Arc:natives-box2d-android:${getArcHash()}"
|
||||
|
||||
//android dependencies magically disappear during compilation, thanks gradle!
|
||||
def sdkFile = new File((String)findSdkDir(), "/platforms/android-29/android.jar")
|
||||
if(sdkFile.exists()) compileOnly files(sdkFile.absolutePath)
|
||||
jcenter() //remove later once google/JetBrains fixes the dependency
|
||||
}
|
||||
|
||||
task deploy(type: Copy){
|
||||
@@ -47,8 +32,8 @@ task deploy(type: Copy){
|
||||
}
|
||||
|
||||
android{
|
||||
buildToolsVersion '29.0.3'
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion '30.0.2'
|
||||
compileSdkVersion 30
|
||||
sourceSets{
|
||||
main{
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
@@ -59,9 +44,13 @@ android{
|
||||
assets.srcDirs = ['assets', 'src/main/assets', '../core/assets/']
|
||||
jniLibs.srcDirs = ['libs']
|
||||
}
|
||||
gp{
|
||||
java.srcDirs = ['srcgp']
|
||||
}
|
||||
|
||||
androidTest.setRoot('tests')
|
||||
}
|
||||
|
||||
packagingOptions{
|
||||
exclude 'META-INF/robovm/ios/robovm.xml'
|
||||
}
|
||||
@@ -73,7 +62,7 @@ android{
|
||||
|
||||
applicationId "io.anuke.mindustry"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 29
|
||||
targetSdkVersion 30
|
||||
|
||||
versionName versionNameResult
|
||||
versionCode = (System.getenv("TRAVIS_BUILD_ID") != null ? System.getenv("TRAVIS_BUILD_ID").toInteger() : vcode)
|
||||
@@ -109,6 +98,14 @@ android{
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes{
|
||||
all{
|
||||
minifyEnabled = true
|
||||
shrinkResources = true
|
||||
proguardFiles("proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
|
||||
if(project.hasProperty("RELEASE_STORE_FILE") || System.getenv("CI") == "true"){
|
||||
buildTypes{
|
||||
release{
|
||||
@@ -116,10 +113,37 @@ android{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Specifies one flavor dimension.
|
||||
flavorDimensions "version"
|
||||
productFlavors{
|
||||
standard{
|
||||
|
||||
}
|
||||
gp{
|
||||
applicationIdSuffix ".gp"
|
||||
versionNameSuffix "-gp"
|
||||
}
|
||||
}
|
||||
}
|
||||
// called every time gradle gets executed, takes the native dependencies of
|
||||
// the natives configuration, and extracts them to the proper libs/ folders
|
||||
// so they get packed with the APK.
|
||||
|
||||
dependencies{
|
||||
implementation project(":core")
|
||||
|
||||
implementation arcModule("backends:backend-android")
|
||||
implementation 'com.jakewharton.android.repackaged:dalvik-dx:9.0.0_r3'
|
||||
|
||||
natives "com.github.Anuken.Arc:natives-android:${getArcHash()}"
|
||||
natives "com.github.Anuken.Arc:natives-freetype-android:${getArcHash()}"
|
||||
|
||||
gpImplementation "com.google.android.gms:play-services-games:21.0.0"
|
||||
gpImplementation "com.google.android.gms:play-services-auth:19.0.0"
|
||||
|
||||
//android dependencies magically disappear during compilation, thanks gradle!
|
||||
def sdkFile = new File((String)findSdkDir(), "/platforms/android-29/android.jar")
|
||||
if(sdkFile.exists()) compileOnly files(sdkFile.absolutePath)
|
||||
}
|
||||
|
||||
task copyAndroidNatives(){
|
||||
configurations.natives.files.each{ jar ->
|
||||
copy{
|
||||
@@ -131,25 +155,7 @@ task copyAndroidNatives(){
|
||||
}
|
||||
|
||||
task run(type: Exec){
|
||||
def path
|
||||
def localProperties = project.file("../local.properties")
|
||||
if(localProperties.exists()){
|
||||
Properties properties = new Properties()
|
||||
localProperties.withInputStream{ instr ->
|
||||
properties.load(instr)
|
||||
}
|
||||
def sdkDir = properties.getProperty('sdk.dir')
|
||||
if(sdkDir){
|
||||
path = sdkDir
|
||||
}else{
|
||||
path = "$System.env.ANDROID_HOME"
|
||||
}
|
||||
}else{
|
||||
path = "$System.env.ANDROID_HOME"
|
||||
}
|
||||
|
||||
def adb = path + "/platform-tools/adb"
|
||||
commandLine "$adb", 'shell', 'am', 'start', '-n', 'io.anuke.mindustry/mindustry.android.AndroidLauncher'
|
||||
commandLine "${findSdkDir()}/platform-tools/adb", 'shell', 'am', 'start', '-n', 'io.anuke.mindustry/mindustry.android.AndroidLauncher'
|
||||
}
|
||||
|
||||
if(!project.ext.hasSprites()){
|
||||
|
||||
8
android/proguard-rules.pro
vendored
Normal file
8
android/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
-dontobfuscate
|
||||
|
||||
#these are essential packages that should not be "optimized" in any way
|
||||
#the main purpose of d8 here is to shrink the absurdly-large google play games libraries
|
||||
-keep class mindustry.** { *; }
|
||||
-keep class arc.** { *; }
|
||||
-keep class net.jpountz.** { *; }
|
||||
-keep class rhino.** { *; }
|
||||
@@ -1,6 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Mindustry</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<resources>
|
||||
|
||||
<style name="ArcTheme" parent="android:Theme">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
@@ -8,5 +7,4 @@
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -15,9 +15,11 @@ import arc.func.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import dalvik.system.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import mindustry.*;
|
||||
import mindustry.game.Saves.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.mod.*;
|
||||
import mindustry.net.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
|
||||
@@ -33,6 +35,9 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
FileChooser chooser;
|
||||
Runnable permCallback;
|
||||
|
||||
Object gpService;
|
||||
Class<?> serviceClass;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
@@ -50,7 +55,7 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
});
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
if(doubleScaleTablets && isTablet(this.getContext())){
|
||||
if(doubleScaleTablets && isTablet(this)){
|
||||
Scl.setAddition(0.5f);
|
||||
}
|
||||
|
||||
@@ -63,7 +68,9 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
|
||||
@Override
|
||||
public rhino.Context getScriptContext(){
|
||||
return AndroidRhinoContext.enter(getContext().getCacheDir());
|
||||
rhino.Context result = AndroidRhinoContext.enter(((Context)AndroidLauncher.this).getCacheDir());
|
||||
result.setClassShutter(Scripts::allowClass);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,8 +78,8 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader loadJar(Fi jar, String mainClass) throws Exception{
|
||||
return new DexClassLoader(jar.file().getPath(), getFilesDir().getPath(), null, getClassLoader());
|
||||
public ClassLoader loadJar(Fi jar, ClassLoader parent) throws Exception{
|
||||
return new DexClassLoader(jar.file().getPath(), getFilesDir().getPath(), null, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,9 +172,20 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
|
||||
try{
|
||||
//new external folder
|
||||
Fi data = Core.files.absolute(getContext().getExternalFilesDir(null).getAbsolutePath());
|
||||
Fi data = Core.files.absolute(((Context)this).getExternalFilesDir(null).getAbsolutePath());
|
||||
Core.settings.setDataDirectory(data);
|
||||
|
||||
//delete unused cache folder to free up space
|
||||
try{
|
||||
Fi cache = Core.settings.getDataDirectory().child("cache");
|
||||
if(cache.exists()){
|
||||
cache.deleteDirectory();
|
||||
}
|
||||
}catch(Throwable t){
|
||||
Log.err("Failed to delete cached folder", t);
|
||||
}
|
||||
|
||||
|
||||
//move to internal storage if there's no file indicating that it moved
|
||||
if(!Core.files.local("files_moved").exists()){
|
||||
Log.info("Moving files to external storage...");
|
||||
@@ -209,6 +227,24 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
|
||||
//TODO enable once GPGS is set up on the GP console
|
||||
if(false && BuildConfig.FLAVOR.equals("gp")){
|
||||
try{
|
||||
if(gpService == null){
|
||||
serviceClass = Class.forName("mindustry.android.GPGameService");
|
||||
gpService = serviceClass.getConstructor().newInstance();
|
||||
}
|
||||
serviceClass.getMethod("onResume", Context.class).invoke(gpService, this);
|
||||
}catch(Exception e){
|
||||
Log.err("Failed to update Google Play Services", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFiles(Intent intent){
|
||||
try{
|
||||
Uri uri = intent.getData();
|
||||
|
||||
@@ -175,7 +175,7 @@ public class AndroidRhinoContext{
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
android.content.Context context = ((AndroidApplication) Core.app).getContext();
|
||||
android.content.Context context = (android.content.Context)((AndroidApplication)Core.app);
|
||||
return new DexClassLoader(dexFile.getPath(), VERSION.SDK_INT >= 21 ? context.getCodeCacheDir().getPath() : context.getCacheDir().getAbsolutePath(), null, getParent()).loadClass(name);
|
||||
}
|
||||
|
||||
|
||||
40
android/srcgp/mindustry/android/GPGameService.java
Normal file
40
android/srcgp/mindustry/android/GPGameService.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package mindustry.android;
|
||||
|
||||
import android.content.*;
|
||||
import arc.util.*;
|
||||
import com.google.android.gms.auth.api.signin.*;
|
||||
import com.google.android.gms.games.*;
|
||||
import mindustry.service.*;
|
||||
|
||||
public class GPGameService extends GameService{
|
||||
private GoogleSignInAccount account;
|
||||
|
||||
public void onResume(Context context){
|
||||
Log.info("[GooglePlayService] Resuming.");
|
||||
|
||||
GoogleSignInAccount current = GoogleSignIn.getLastSignedInAccount(context);
|
||||
|
||||
GoogleSignInOptions options =
|
||||
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
|
||||
.requestScopes(Games.SCOPE_GAMES_SNAPSHOTS)
|
||||
.build();
|
||||
|
||||
if(GoogleSignIn.hasPermissions(current, options.getScopeArray())){
|
||||
this.account = current;
|
||||
Log.info("Already signed in to Google Play Games.");
|
||||
}else{
|
||||
GoogleSignIn.getClient(context, options).silentSignIn().addOnCompleteListener(complete -> {
|
||||
if(!complete.isSuccessful()){
|
||||
if(complete.getException() != null){
|
||||
Log.err("Failed to sign in to Google Play Games.", complete.getException());
|
||||
}else{
|
||||
Log.warn("Failed to sign in to Google Play Games.");
|
||||
}
|
||||
}else{
|
||||
this.account = complete.getResult();
|
||||
Log.info("Signed in to Google Play Games.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user