11apply plugin : ' com.android.application'
22
3+ def examplesJar = project(' :jme3-examples' ). tasks. named(' jar' )
4+
35android {
46 namespace " org.jmonkeyengine.jme3androidexamples"
57 compileSdk 34
@@ -16,12 +18,13 @@ android {
1618 targetSdk 34 // Android 14
1719 versionCode 1
1820 versionName " 1.0" // TODO: from settings.gradle
21+ testInstrumentationRunner " androidx.test.runner.AndroidJUnitRunner"
1922 }
2023
2124 buildTypes {
2225 release {
2326 minifyEnabled false
24- proguardFiles getDefaultProguardFile(' proguard-android.txt' ), ' proguard-rules.pro'
27+ proguardFiles getDefaultProguardFile(' proguard-android-optimize .txt' ), ' proguard-rules.pro'
2528 }
2629 }
2730
@@ -40,23 +43,117 @@ android {
4043 srcDir ' ../jme3-testdata/src/main/resources'
4144 srcDir ' ../jme3-examples/src/main/resources'
4245 }
46+ jniLibs {
47+ srcDir ' ../build/native/openalsoft'
48+ srcDir ' ../build/native/decode'
49+ srcDir ' ../build/native/allocator'
50+ }
4351 }
4452 }
4553}
4654
4755dependencies {
4856 implementation fileTree(dir : ' libs' , include : [' *.jar' ])
49- testImplementation libs. junit4
50- implementation libs. androidx. appcompat
51-
57+ testImplementation platform(libs. junit. bom)
58+ testImplementation libs. junit. jupiter
59+ testRuntimeOnly libs. junit. platform. launcher
60+ androidTestImplementation libs. junit4
61+ androidTestImplementation libs. androidx. test. runner
62+ implementation libs. androidx. fragment
5263 implementation project(' :jme3-core' )
5364 implementation project(' :jme3-android' )
5465 implementation project(' :jme3-android-native' )
5566 implementation project(' :jme3-effects' )
5667 implementation project(' :jme3-jbullet' )
68+ implementation project(' :jme3-jogg' )
5769 implementation project(' :jme3-networking' )
5870 implementation project(' :jme3-niftygui' )
5971 implementation project(' :jme3-plugins' )
72+ implementation project(' :jme3-plugins-json' )
73+ implementation project(' :jme3-plugins-json-gson' )
6074 implementation project(' :jme3-terrain' )
61- implementation fileTree(dir : ' ../jme3-examples/build/libs' , include : [' *.jar' ], exclude : [' *sources*.*' ])
75+ implementation files(examplesJar. flatMap { it. archiveFile })
76+ }
77+
78+ tasks. named(' preBuild' ) {
79+ dependsOn examplesJar
80+ if (buildNativeProjects == " true" ) {
81+ dependsOn ' :jme3-android-native:updatePreCompiledOpenAlSoftLibs'
82+ dependsOn ' :jme3-android-native:updatePreCompiledLibs'
83+ dependsOn ' :jme3-android-native:updatePreCompiledLibsBufferAllocator'
84+ } else if (skipPrebuildLibraries != " true" ) {
85+ dependsOn ' :jme3-android-native:copyPreCompiledOpenAlSoftLibs'
86+ dependsOn ' :jme3-android-native:copyPreCompiledLibs'
87+ dependsOn ' :jme3-android-native:copyPreCompiledLibsBufferAllocator'
88+ }
89+ }
90+
91+ tasks. register(' installAndroidExamples' , Exec ) {
92+ group = ' application'
93+ description = ' Install the Android examples selector on a connected emulator or device.'
94+
95+ dependsOn tasks. named(' assembleDebug' )
96+
97+ doFirst {
98+ def adbExecutable = findAdbExecutable()
99+ if (adbExecutable == null ) {
100+ throw new GradleException (" ADB not found. Set -Pandroid.sdk.path, ANDROID_HOME, or ANDROID_SDK_ROOT." )
101+ }
102+ def apkFile = layout. buildDirectory. file(' outputs/apk/debug/jme3-android-examples-debug.apk' ). get(). asFile
103+ if (! apkFile. isFile()) {
104+ throw new GradleException (" Debug APK not found at ${ apkFile} ." )
105+ }
106+ executable adbExecutable. absolutePath
107+ args ' install' , ' -r' , apkFile. absolutePath
108+ }
109+ }
110+
111+ tasks. register(' runAndroidExamples' , Exec ) {
112+ group = ' application'
113+ description = ' Install and launch Android examples on a connected emulator or device. Use -Pexample=<class> to run a specific test directly.'
114+
115+ dependsOn tasks. named(' installAndroidExamples' )
116+
117+ doFirst {
118+ def adbExecutable = findAdbExecutable()
119+ if (adbExecutable == null ) {
120+ throw new GradleException (" ADB not found. Set -Pandroid.sdk.path, ANDROID_HOME, or ANDROID_SDK_ROOT." )
121+ }
122+ executable adbExecutable. absolutePath
123+
124+ def exampleClass = project. findProperty(' example' )?. toString()?. trim()
125+ if (exampleClass) {
126+ args ' shell' , ' am' , ' start' ,
127+ ' -n' , ' org.jmonkeyengine.jme3androidexamples/.TestActivity' ,
128+ ' --es' , ' Selected_App_Class' , exampleClass,
129+ ' --ez' , ' Enable_Mouse_Events' , ' true' ,
130+ ' --ez' , ' Enable_Joystick_Events' , ' false' ,
131+ ' --ez' , ' Enable_Key_Events' , ' true' ,
132+ ' --ez' , ' Verbose_Logging' , ' false'
133+ } else {
134+ args ' shell' , ' am' , ' start' ,
135+ ' -n' , ' org.jmonkeyengine.jme3androidexamples/.MainActivity'
136+ }
137+ }
138+ }
139+
140+ def findAdbExecutable () {
141+ def adbName = System . properties[' os.name' ]. toLowerCase(). contains(' windows' ) ? ' adb.exe' : ' adb'
142+ def sdkDirs = []
143+ if (project. findProperty(' android.sdk.path' )) {
144+ sdkDirs << file(project. findProperty(' android.sdk.path' ))
145+ }
146+ if (System . env. ANDROID_HOME ) {
147+ sdkDirs << file(System . env. ANDROID_HOME )
148+ }
149+ if (System . env. ANDROID_SDK_ROOT ) {
150+ sdkDirs << file(System . env. ANDROID_SDK_ROOT )
151+ }
152+ sdkDirs << file(" ${ System.properties['user.home']} /Android/Sdk" )
153+
154+ def expandedSdkDirs = sdkDirs. collectMany { sdkDir ->
155+ [sdkDir, new File (sdkDir, ' Sdk' )]
156+ }. unique { it. absolutePath }
157+
158+ return expandedSdkDirs. collect { new File (new File (it, ' platform-tools' ), adbName) }. find { it. isFile() }
62159}
0 commit comments