diff --git a/.gitignore b/.gitignore index ee6b582a0..a064f2274 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,16 @@ *.VC.db *.VC.VC.opendb +# Android build results +android/.gradle/ +android/gradle/ +android/build/ +android/app/build/ +android/app/.externalNativeBuild/ +android/local.properties +*.iml + # Build results -[Aa]ndroid/ [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ diff --git a/android/app/CMakeLists.txt b/android/app/CMakeLists.txt new file mode 100644 index 000000000..4ed011768 --- /dev/null +++ b/android/app/CMakeLists.txt @@ -0,0 +1,107 @@ +# +# Copyright (C) The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +cmake_minimum_required(VERSION 3.4.1) + +# build native_app_glue as a static lib +set(${CMAKE_C_FLAGS}, "${CMAKE_C_FLAGS}") +# now build app's shared lib +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -Werror") + +add_library(classicube SHARED + ../../src/Program.c + ../../src/_fttype1.c + ../../src/IsometricDrawer.c + ../../src/_ftcid.c + ../../src/Builder.c + ../../src/ExtMath.c + ../../src/_ftbitmap.c + ../../src/Utils.c + ../../src/Camera.c + ../../src/Game.c + ../../src/Window.c + ../../src/_ftbase.c + ../../src/Graphics.c + ../../src/_type1cid.c + ../../src/Deflate.c + ../../src/_cff.c + ../../src/_ftsynth.c + ../../src/String.c + ../../src/LWidgets.c + ../../src/Options.c + ../../src/Drawer2D.c + ../../src/Server.c + ../../src/Entity.c + ../../src/Drawer.c + ../../src/Vorbis.c + ../../src/Protocol.c + ../../src/World.c + ../../src/PickedPosRenderer.c + ../../src/Platform.c + ../../src/LScreens.c + ../../src/_truetype.c + ../../src/_ftglyph.c + ../../src/Model.c + ../../src/_autofit.c + ../../src/Vectors.c + ../../src/_raster.c + ../../src/HeldBlockRenderer.c + ../../src/Inventory.c + ../../src/Launcher.c + ../../src/Block.c + ../../src/LWeb.c + ../../src/Stream.c + ../../src/Lighting.c + ../../src/Resources.c + ../../src/PackedCol.c + ../../src/Screens.c + ../../src/Formats.c + ../../src/_sfnt.c + ../../src/Bitmap.c + ../../src/EntityComponents.c + ../../src/_pshinter.c + ../../src/Http.c + ../../src/MapRenderer.c + ../../src/Audio.c + ../../src/_ftinit.c + ../../src/Event.c + ../../src/Logger.c + ../../src/Widgets.c + ../../src/TexturePack.c + ../../src/Menus.c + ../../src/BlockPhysics.c + ../../src/_psmodule.c + ../../src/Chat.c + ../../src/Gui.c + ../../src/AxisLinesRenderer.c + ../../src/Picking.c + ../../src/_type1.c + ../../src/_smooth.c + ../../src/_psaux.c + ../../src/Generator.c + ../../src/Input.c + ../../src/Particle.c + ../../src/Physics.c + ../../src/SelectionBox.c + ../../src/EnvRenderer.c + ) + +# add lib dependencies +target_link_libraries(classicube + android + EGL + GLESv2 + log) diff --git a/android/app/build.gradle b/android/app/build.gradle new file mode 100644 index 000000000..7c4bed404 --- /dev/null +++ b/android/app/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + + defaultConfig { + applicationId = 'com.classicube.ClassiCube' + minSdkVersion 14 + targetSdkVersion 28 + externalNativeBuild { + cmake { + arguments '-DANDROID_STL=c++_static' + } + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), + 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + version '3.10.2' + path 'CMakeLists.txt' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' +} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..7d18b9c5c --- /dev/null +++ b/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/java/com/classicube/MainActivity.java b/android/app/src/main/java/com/classicube/MainActivity.java new file mode 100644 index 000000000..3a4711a60 --- /dev/null +++ b/android/app/src/main/java/com/classicube/MainActivity.java @@ -0,0 +1,553 @@ +package com.classicube; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.Semaphore; +import java.util.concurrent.ConcurrentLinkedQueue; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.ClipboardManager; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Configuration; +import android.graphics.PixelFormat; +import android.net.Uri; +import android.os.Bundle; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.Display; +import android.view.InputQueue; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.WindowManager; +import android.view.View; +import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.view.Window; +import android.view.inputmethod.InputMethodManager; + +// implements InputQueue.Callback +public class MainActivity extends Activity implements SurfaceHolder.Callback2 { + LauncherView curView; + + // ====================================== + // -------------- COMMANDS -------------- + // ====================================== + class NativeCmdArgs { public int cmd, arg1, arg2, arg3; public Surface sur; } + Queue nativeCmds = new ConcurrentLinkedQueue(); + Queue freeCmds = new ConcurrentLinkedQueue(); + + NativeCmdArgs getCmdArgs() { + NativeCmdArgs args = freeCmds.poll(); + return args != null ? args : new NativeCmdArgs(); + } + + void pushCmd(int cmd) { + NativeCmdArgs args = getCmdArgs(); + args.cmd = cmd; + nativeCmds.add(args); + } + + void pushCmd(int cmd, int a1) { + NativeCmdArgs args = getCmdArgs(); + args.cmd = cmd; + args.arg1 = a1; + nativeCmds.add(args); + } + + void pushCmd(int cmd, int a1, int a2, int a3) { + NativeCmdArgs args = getCmdArgs(); + args.cmd = cmd; + args.arg1 = a1; + args.arg2 = a2; + args.arg3 = a3; + nativeCmds.add(args); + } + + void pushCmd(int cmd, Surface surface) { + NativeCmdArgs args = getCmdArgs(); + args.cmd = cmd; + args.sur = surface; + nativeCmds.add(args); + } + + final static int CMD_KEY_DOWN = 0; + final static int CMD_KEY_UP = 1; + final static int CMD_KEY_CHAR = 2; + + final static int CMD_MOUSE_DOWN = 3; + final static int CMD_MOUSE_UP = 4; + final static int CMD_MOUSE_MOVE = 5; + + final static int CMD_WIN_CREATED = 6; + final static int CMD_WIN_DESTROYED = 7; + final static int CMD_WIN_RESIZED = 8; + final static int CMD_WIN_REDRAW = 9; + + final static int CMD_APP_START = 10; + final static int CMD_APP_STOP = 11; + final static int CMD_APP_RESUME = 12; + final static int CMD_APP_PAUSE = 13; + final static int CMD_APP_DESTROY = 14; + + final static int CMD_GOT_FOCUS = 15; + final static int CMD_LOST_FOCUS = 16; + final static int CMD_CONFIG_CHANGED = 17; + final static int CMD_LOW_MEMORY = 18; + + // ====================================== + // --------------- EVENTS --------------- + // ====================================== + static boolean gameHooked; + + @Override + protected void onCreate(Bundle savedInstanceState) { + Log.i("CC_WIN", "CREATE EVENT"); + Window window = getWindow(); + Log.i("CC_WIN", "GAME RUNNING?" + gameHooked); + gameHooked = true; + //window.takeSurface(this); + //window.takeInputQueue(this); + // TODO: Should this be RGBA_8888?? + window.setFormat(PixelFormat.RGBX_8888); + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + requestWindowFeature(Window.FEATURE_NO_TITLE); + // TODO: semaphore for destroyed and surfaceDestroyed + + Log.i("CC_WIN", "handing off to native.."); + System.loadLibrary("classicube"); + runGameAsync(); + super.onCreate(savedInstanceState); + } + + + /*@Override + public boolean dispatchKeyEvent(KeyEvent event) { + int action = event.getAction(); + int code = event.getKeyCode(); + + if (action == KeyEvent.ACTION_DOWN) { + pushCmd(CMD_KEY_DOWN, keyCode); + + int keyChar = event.getUnicodeChar(); + if (keyChar != 0) pushCmd(CMD_KEY_CHAR, keyChar); + return true; + } else if (action == KeyEvent.ACTION_UP) { + pushCmd(CMD_KEY_UP, keyCode); + return true; + } + return super.dispatchKeyEvent(event); + }*/ + + void pushTouch(int cmd, MotionEvent event, int i) { + int id = event.getPointerId(i); + // TODO: Pass float to jni + int x = (int)event.getX(i); + int y = (int)event.getY(i); + pushCmd(cmd, id, x, y); + } + + boolean handleTouchEvent(MotionEvent event) { + switch (event.getActionMasked()) { + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + pushTouch(CMD_MOUSE_DOWN, event, event.getActionIndex()); + break; + + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + pushTouch(CMD_MOUSE_UP, event, event.getActionIndex()); + break; + + case MotionEvent.ACTION_MOVE: + for (int i = 0; i < event.getPointerCount(); i++) { + pushTouch(CMD_MOUSE_MOVE, event, i); + } + } + return true; + } + + public boolean onKeyDown(int keyCode, KeyEvent event) { + // TODO: not always handle (use Window_MapKey) + pushCmd(CMD_KEY_DOWN, keyCode); + + int keyChar = event.getUnicodeChar(); + if (keyChar != 0) pushCmd(CMD_KEY_CHAR, keyChar); + return true; + } + + public boolean onKeyUp(int keyCode, KeyEvent event) { + // TODO: not always handle (use Window_MapKey) + pushCmd(CMD_KEY_UP, keyCode); + return true; + } + + @Override + protected void onStart() { + super.onStart(); + pushCmd(CMD_APP_START); + } + + @Override + protected void onStop() { + super.onStop(); + pushCmd(CMD_APP_STOP); + } + + @Override + protected void onResume() { + attachSurface(); + super.onResume(); + pushCmd(CMD_APP_RESUME); + } + + @Override + protected void onPause() { + detachSurface(); + super.onPause(); + pushCmd(CMD_APP_PAUSE); + } + + @Override + public void onWindowFocusChanged(boolean hasFocus) { + super.onWindowFocusChanged(hasFocus); + pushCmd(hasFocus ? CMD_GOT_FOCUS : CMD_LOST_FOCUS); + } + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + //pushCmd(CMD_CONFIG_CHANGED); + // not needed because it's the surfaceChanged event that matters + } + @Override + public void onLowMemory() { super.onLowMemory(); pushCmd(CMD_LOW_MEMORY); } + + @Override + public void onDestroy() { + Log.i("CC_WIN", "APP DESTROYED"); + super.onDestroy(); + } + + // this is called on the game thread + public void processEvents() { + for (;;) { + NativeCmdArgs c = nativeCmds.poll(); + if (c == null) return; + + switch (c.cmd) { + case CMD_KEY_DOWN: processKeyDown(c.arg1); break; + case CMD_KEY_UP: processKeyUp(c.arg1); break; + case CMD_KEY_CHAR: processKeyChar(c.arg1); break; + + case CMD_MOUSE_DOWN: processMouseDown(c.arg1, c.arg2, c.arg3); break; + case CMD_MOUSE_UP: processMouseUp(c.arg1, c.arg2, c.arg3); break; + case CMD_MOUSE_MOVE: processMouseMove(c.arg1, c.arg2, c.arg3); break; + + case CMD_WIN_CREATED: processSurfaceCreated(c.sur); break; + case CMD_WIN_DESTROYED: processSurfaceDestroyed(); break; + case CMD_WIN_RESIZED: processSurfaceResized(c.sur); break; + case CMD_WIN_REDRAW: processSurfaceRedrawNeeded(); break; + + case CMD_APP_START: processOnStart(); break; + case CMD_APP_STOP: processOnStop(); break; + case CMD_APP_RESUME: processOnResume(); break; + case CMD_APP_PAUSE: processOnPause(); break; + case CMD_APP_DESTROY: processOnDestroy(); break; + + case CMD_GOT_FOCUS: processOnGotFocus(); break; + case CMD_LOST_FOCUS: processOnLostFocus(); break; + //case CMD_CONFIG_CHANGED: processOnConfigChanged(); break; + case CMD_LOW_MEMORY: processOnLowMemory(); break; + } + + c.sur = null; // don't keep a reference to it + freeCmds.add(c); + } + } + + native void processKeyDown(int code); + native void processKeyUp(int code); + native void processKeyChar(int code); + + native void processMouseDown(int id, int x, int y); + native void processMouseUp(int id, int x, int y); + native void processMouseMove(int id, int x, int y); + + native void processSurfaceCreated(Surface sur); + native void processSurfaceDestroyed(); + native void processSurfaceResized(Surface sur); + native void processSurfaceRedrawNeeded(); + + native void processOnStart(); + native void processOnStop(); + native void processOnResume(); + native void processOnPause(); + native void processOnDestroy(); + + native void processOnGotFocus(); + native void processOnLostFocus(); + //native void processOnConfigChanged(); + native void processOnLowMemory(); + + native void runGameAsync(); + + // ====================================== + // --------------- VIEWS ---------------- + // ====================================== + public void surfaceCreated(SurfaceHolder holder) { + Log.i("CC_WIN", "win created " + holder.getSurface()); + pushCmd(CMD_WIN_CREATED, holder.getSurface()); + } + + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + Log.i("CC_WIN", "win changed " + holder.getSurface()); + pushCmd(CMD_WIN_RESIZED, holder.getSurface()); + } + + final Semaphore winDestroyedSem = new Semaphore(0, true); + public void surfaceDestroyed(SurfaceHolder holder) { + Log.i("CC_WIN", "win destroyed " + holder.getSurface()); + // per the android docs for SurfaceHolder.Callback + // "If you have a rendering thread that directly accesses the surface, you must ensure + // that thread is no longer touching the Surface before returning from this function." + Log.i("CC_WIN", "cur holder " + holder); + Log.i("CC_WIN", "cur view" + curView.getHolder()); + curView.getHolder().removeCallback(this); // or just holder?? + + //08-02 21:03:02.967: E/BufferQueueProducer(1350): [SurfaceView - com.classicube.ClassiCube/com.classicube.MainActivity#0] disconnect: not connected (req=2) + //08-02 21:03:02.968: E/SurfaceFlinger(1350): Failed to find layer (SurfaceView - com.classicube.ClassiCube/com.classicube.MainActivity#0) in layer parent (no-parent). + + pushCmd(CMD_WIN_DESTROYED); + try { + winDestroyedSem.acquire(); + } catch (InterruptedException e) { } + } + + // Game calls this on its thread to notify the main thread + // that it is safe to destroy the window surface now + public void processedSurfaceDestroyed() { + winDestroyedSem.release(); + } + + public void surfaceRedrawNeeded(SurfaceHolder holder) { + Log.i("CC_WIN", "win dirty " + holder.getSurface()); + pushCmd(CMD_WIN_REDRAW); + } + + void attachSurface() { + curView = new LauncherView(this); + curView.getHolder().addCallback(this); + curView.getHolder().setFormat(PixelFormat.RGBX_8888); + + setContentView(curView); + curView.requestFocus(); + } + + void detachSurface() { + // can't use null.. TODO is there a better way? + setContentView(new View(this)); + } + + class LauncherView extends SurfaceView { + + public LauncherView(Context context) { super(context); } + + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + return MainActivity.this.handleTouchEvent(ev) || super.dispatchTouchEvent(ev); + } + } + + // ====================================== + // -------------- PLATFORM -------------- + // ====================================== + public void setupForGame() { + // Once a surface has been locked for drawing with canvas, can't ever be detached + // This means trying to attach an OpenGL ES context to the surface will fail + // So just destroy the current surface and make a new one + runOnUiThread(new Runnable() { + public void run() { + detachSurface(); + attachSurface(); + } + }); + } + + public void startOpen(String url) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + if (intent.resolveActivity(getPackageManager()) != null) { + startActivity(intent); + } + } + + public String getExternalAppDir() { + return getExternalFilesDir(null).getAbsolutePath(); + } + + public String getCmdLineArg(int i) { + Intent intent = getIntent(); + if (intent == null) return null; + + String[] all = intent.getStringArrayExtra("com.classicube.args"); + if (all == null) return null; + return i >= all.length ? null : all[i]; + } + + // ====================================== + // --------------- WINDOW --------------- + // ====================================== + public void setWindowTitle(String str) { setTitle(str); } + + public void openKeyboard() { + InputMethodManager input = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); + View view = getWindow().getDecorView(); + input.showSoftInput(view, 0); + } + + public void closeKeyboard() { + InputMethodManager input = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); + View view = getWindow().getDecorView(); + input.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + + public String getClipboardText() { + ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); + CharSequence chars = clipboard.getText(); + return chars == null ? null : chars.toString(); + } + + public void setClipboardText(String str) { + ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(str); + } + + DisplayMetrics getMetrics() { + DisplayMetrics dm = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(dm); + return dm; + } + + // map android 160 baseline dpi + public float getDpiX() { return getMetrics().xdpi / 160.0f; } + public float getDpiY() { return getMetrics().ydpi / 160.0f; } + + final Semaphore dialogSem = new Semaphore(0, true); + + public void showAlert(final String title, final String message) { + //final Activity activity = this; + runOnUiThread(new Runnable() { + public void run() { + AlertDialog.Builder dlg = new AlertDialog.Builder(MainActivity.this, AlertDialog.THEME_HOLO_DARK); + dlg.setTitle(title); + dlg.setMessage(message); + dlg.setPositiveButton("Close", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialogSem.release(); + } + }); + dlg.setCancelable(false); + dlg.create().show(); + } + }); + + // wait for dialog to be closed + + } + + // ====================================== + // ---------------- HTTP ---------------- + // ====================================== + HttpURLConnection conn; + InputStream src; + byte[] readCache = new byte[8192]; + + public int httpInit(String url, String method) { + url = url.replace("http://", "https://"); + try { + conn = (HttpURLConnection)new URL(url).openConnection(); + conn.setDoInput(true); + conn.setRequestMethod(method); + conn.setInstanceFollowRedirects(true); + return 0; + } catch (Exception ex) { + return httpOnError(ex); + } + } + + public void httpSetHeader(String name, String value) { + conn.setRequestProperty(name, value); + } + + public int httpSetData(byte[] data) { + try { + conn.setDoOutput(true); + conn.getOutputStream().write(data); + conn.getOutputStream().flush(); + return 0; + } catch (Exception ex) { + return httpOnError(ex); + } + } + + public int httpPerform() { + int len; + try { + conn.connect(); + Map> all = conn.getHeaderFields(); + + for (Map.Entry> h : all.entrySet()) { + String key = h.getKey(); + for (String value : h.getValue()) { + if (key == null) { + httpParseHeader(value); + } else { + httpParseHeader(key + ":" + value); + } + } + } + + src = conn.getInputStream(); + while ((len = src.read(readCache)) > 0) { + httpAppendData(readCache, len); + } + + httpFinish(); + return 0; + } catch (Exception ex) { + return httpOnError(ex); + } + } + + void httpFinish() { + conn = null; + try { + src.close(); + } catch (Exception ex) { } + src = null; + } + + // TODO: Should we prune this list? + List errors = new ArrayList(); + + int httpOnError(Exception ex) { + ex.printStackTrace(); + httpFinish(); + errors.add(ex.getMessage()); + return -errors.size(); // don't want 0 as an error code + } + + public String httpDescribeError(int res) { + res = -res - 1; + return res >= 0 && res < errors.size() ? errors.get(res) : null; + } + + native void httpParseHeader(String header); + native void httpAppendData(byte[] data, int len); +} diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..cde69bccc Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..c133a0cbd Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..bfa42f0e7 Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..324e72cdd Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..045e125f3 --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + + diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 000000000..eef418019 --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,21 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.3.1' + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 000000000..7bef3c232 --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,20 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true + diff --git a/android/gradlew b/android/gradlew new file mode 100644 index 000000000..91a7e269e --- /dev/null +++ b/android/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat new file mode 100644 index 000000000..aec99730b --- /dev/null +++ b/android/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 000000000..573abcb32 --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1,2 @@ +include ':app' +