Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android examples: basic structure for an android example app module #38

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Ignore Gradle project-specific cache directory
.gradle

.vscode
.idea

*.iml
/local.properties
.DS_Store

/buildSrc/build
/buildSrc/bin
Expand All @@ -15,3 +19,6 @@
/jme3-alloc-examples/bin
/jme3-alloc-examples/*.so
/jme3-alloc-examples/*.log

/jme3-alloc-android-example/build
/jme3-alloc-android-example/bin
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import com.jme3.build.actions.Permissioning;
import com.jme3.build.actions.ScriptExecutor;

/**
* The abstract untity for running unix scripts in bash shell environments.
* The abstract entity for running unix scripts in bash shell environments.
* It consists of 2 sequential tasks: a [permissioning] task and a [script-executor] task.
*
* @author pavl_g
Expand Down
22 changes: 22 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
compileMacX86Property=false
compileWindowsX86Property=false
compileLinuxX86Property=true

# 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.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# 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
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
42 changes: 42 additions & 0 deletions helper-scripts/project-impl/compile-android-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# source directory from the gradle wrapper working directory
source "./helper-scripts/abstract/abstract-compile.sh"
source "./helper-scripts/project-impl/variables.sh"

java_home=${1}

function compileAndroidArm64Debug() {
getCurrentSystem
echo -e "Compiling debug Android arm64 binaries"
# compile an aarch64 binary on the arm64-v8a directory with min_sdk = 21 (android lollipop)
compile "$android_clang" "$native_sources" "$compiler_options_android_debug -target ${arm64}${min_android_sdk}" "$native_headers" "$java_home" "${output}/${arm64_lib_directory}/${lib}"
return $?
}

function compileAndroidArm32Debug() {
getCurrentSystem
echo -e "Compiling debug Android arm32 binaries"
# compile an arm32 binary on the armeabi-v7a directory with min_sdk = 21 (android lollipop)
compile "$android_clang" "$native_sources" "$compiler_options_android_debug -target ${arm32}${min_android_sdk}" "$native_headers" "$java_home" "${output}/${arm32_lib_directory}/${lib}"
return $?
}

function compileAndroidIntel32Debug() {
getCurrentSystem
echo -e "Compiling debug Android intel32 binaries"
compile "$android_clang" "$native_sources" "$compiler_options_android_debug -target ${intel32}${min_android_sdk}" "$native_headers" "$java_home" "${output}/${intel32_lib_directory}/${lib}"
return $?
}

function compileAndroidIntel64Debug() {
getCurrentSystem
echo -e "Compiling debug Android intel64 binaries"
compile "$android_clang" "$native_sources" "$compiler_options_android_debug -target ${intel64}${min_android_sdk}" "$native_headers" "$java_home" "${output}/${intel64_lib_directory}/${lib}"
return $?
}

compileAndroidArm64Debug
compileAndroidArm32Debug
compileAndroidIntel64Debug
compileAndroidIntel32Debug
3 changes: 2 additions & 1 deletion helper-scripts/project-impl/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ compiler_optionsX86_64="-shared -m64 -g0 -s"
compiler_optionsX86_64_debug="-shared -m64 -g3 -D__ENABLE_DEBUG_LOGGER -D__ENABLE_LOGGER"

# android compiler properties
android_clang="$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
NDK_HOME=$ANDROID_NDK_LATEST_HOME
android_clang="$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"

min_android_sdk=21

Expand Down
47 changes: 47 additions & 0 deletions jme3-alloc-android-example/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import com.jme3.build.util.JarMetadata;

plugins {
id 'com.android.application'
}

final String dependencyName =
"${JarMetadata.BASE_NAME.getData()}-android-${JarMetadata.VERSION.getData()}${JarMetadata.EXT.getData()}"

android {
namespace 'com.jme3.alloc.android.example'
compileSdk 33

defaultConfig {
applicationId "com.jme3.alloc.android.example"
minSdk 22
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation files("../jme3-alloc-examples/build/libs/jme3-alloc-examples.jar")
implementation files("../jme3-alloc-examples/build/libs/dependencies/${dependencyName}")
}
21 changes: 21 additions & 0 deletions jme3-alloc-android-example/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.jme3.alloc.android.example;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.jme3.alloc.android.example", appContext.getPackageName());
}
}
25 changes: 25 additions & 0 deletions jme3-alloc-android-example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AllocExamples"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.alloc.android.example;

import com.jme3.alloc.examples.StressLauncher;

import java.util.concurrent.locks.ReentrantLock;

/**
* Launches the stress launcher on android on another thread, open the profiler and press [start].
*
* @author pavl_g
*/
public final class AndroidLauncher extends Thread {
private final ReentrantLock reentrantLock = new ReentrantLock();
private boolean started = false;
@Override
public void run() {
try {
reentrantLock.lock();
this.started = true;
StressLauncher.main(null);
} catch (InterruptedException e) {
System.err.println("Interrupted");
} catch (IllegalThreadStateException e) {
System.err.println("Cannot start correctly, please restart the application !");
} finally {
this.started = true;
reentrantLock.unlock();
}
}

public boolean isStarted() {
return started;
}

public void setStop() {
StressLauncher.setStop(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.alloc.android.example;

/**
* Represents a component id.
*
* @author pavl_g
*/
public enum ComponentId {
/**
* The start button ID.
*/
START(R.id.start),

/**
* The terminate button ID.
*/
TERMINATE(R.id.terminate);

public final int id;

ComponentId(int id) {
this.id = id;
}

public int getId() {
return id;
}
}