Skip to content

Commit

Permalink
feat: add android gradle for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Jun 26, 2023
1 parent 16670c8 commit 7326153
Show file tree
Hide file tree
Showing 16 changed files with 686 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
examples/***/android/gradle
examples/***/android/build
examples/***/android/.gradle
***/target
/Cargo.lock
32 changes: 27 additions & 5 deletions examples/multiple_joysticks_mobile/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/multiple_joysticks_mobile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ label = "Multiple Joystick"
# Important: this solve the [issue](https://github.com/bevyengine/bevy/issues/8322)
#
[patch.crates-io]
android-activity = { git = "https://github.com/MarijnS95/android-activity/", branch = "na-resize" }
android-activity = { git = "https://github.com/rust-mobile/android-activity", rev = "79e03e08fbf70e374cb88d8ef8c89acaa006bbfc" }
24 changes: 24 additions & 0 deletions examples/multiple_joysticks_mobile/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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:icon="@mipmap/ic_launcher"
android:label="Multiple Joysticks"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.lib_name" android:value="multiple_joysticks_mobile" />
</activity>
</application>

</manifest>
151 changes: 151 additions & 0 deletions examples/multiple_joysticks_mobile/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
buildscript {
apply from: "config.gradle"
repositories {
google()
mavenCentral()
}
dependencies {
classpath libraries.androidGradlePlugin
classpath libraries.kotlinGradlePlugin
classpath "org.mozilla.rust-android-gradle:plugin:0.9.3"
}
}

plugins {
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.3"
}

allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply from: "config.gradle"

dependencies {
implementation libraries.kotlinStdLib
implementation libraries.androidxAppcompat
}

android {
namespace getExportPackageName()
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
ndkVersion versions.ndkVersion

compileOptions {
sourceCompatibility versions.javaVersion
targetCompatibility versions.javaVersion
}

kotlinOptions {
jvmTarget = versions.javaVersion
}

defaultConfig {
// The default ignore pattern for the "assets" directory includes hidden files and directories which are used by Crossbow projects.
aaptOptions {
ignoreAssetsPattern "!.svn:!.git:!.gitignore:!.ds_store:!*.scc:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
}

// Feel free to modify the application id to your own.
applicationId getExportPackageName()
versionCode getExportVersionCode()
versionName getExportVersionName()
minSdkVersion getExportMinSdkVersion()
targetSdkVersion getExportTargetSdkVersion()

missingDimensionStrategy "products", "template"
}

lintOptions {
abortOnError false
disable "MissingTranslation", "UnusedResources"
}

sourceSets {
main {
manifest.srcFile "AndroidManifest.xml"
java.srcDirs = ["src"]
assets.srcDirs = ["../assets"]
res.srcDirs = ["../assets/android-res"]
}
// debug.jniLibs.srcDirs = ["../libs/debug"]
// release.jniLibs.srcDirs = ["../libs/release"]
}
}

apply plugin: "org.mozilla.rust-android-gradle.rust-android"

cargo {
module = "../"
libname = "multiple_joysticks_mobile"
targets = [
// "arm",
"arm64",
// "x86",
// "x86_64"
]
targetDirectory = "../target"
}

//
//
// Automate copy std libc
//
//

import org.apache.tools.ant.taskdefs.condition.Os

tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebug' || task.name == 'bundleDebug') {
cargo.profile = "debug"
} else if (task.name == 'assembleRelease' || task.name == 'bundleRelease') {
cargo.profile = "release"
}
if (task.name == 'mergeDebugJniLibFolders' || task.name == 'mergeReleaseJniLibFolders') {
task.dependsOn 'cargoBuild'
}
for (target in cargo.targets) {
if (task.name == "cargoBuild${target.capitalize()}") {
task.dependsOn "copy_libc++_shared${target.capitalize()}"
}
}
}

for (target in cargo.targets) {
tasks.register("copy_libc++_shared${target.capitalize()}", Copy) {
def ndkDir = android.ndkDirectory
def hostTag
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
if (Os.isArch("x86_64") || Os.isArch("amd64")) {
hostTag = "windows-x86_64"
} else {
hostTag = "windows"
}
} else if (Os.isFamily(Os.FAMILY_MAC)) {
hostTag = "darwin-x86_64"
} else {
hostTag = "linux-x86_64"
}

def (abi, archTriple) = [
arm: ['armeabi-v7a', 'arm-linux-androideabi'],
arm64: ['arm64-v8a', 'aarch64-linux-android'],
x86: ['x86', 'i686-linux-android'],
x86_64: ['x86_64', 'x86_64-linux-android'],
][target]

def from_path = "$ndkDir/toolchains/llvm/prebuilt/$hostTag/sysroot/usr/lib/$archTriple/libc++_shared.so"
def into_path = layout.buildDirectory.dir("rustJniLibs/android/$abi")

assert file(from_path).exists()

from from_path
into into_path
}
}
86 changes: 86 additions & 0 deletions examples/multiple_joysticks_mobile/android/config.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
ext.versions = [
androidGradlePlugin: "7.4.2",
compileSdk : 33,
minSdk : 26,
targetSdk : 31,
buildTools : "30.0.3",
kotlinVersion : "1.6.21",
fragmentVersion : "1.3.6",
appcompatVersion : "1.4.0",
nexusPublishVersion: "1.1.0",
javaVersion : 17,
ndkVersion : "25.1.8937393"
]

ext.libraries = [
androidGradlePlugin: "com.android.tools.build:gradle:$versions.androidGradlePlugin",
kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion",
kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlinVersion",
androidxFragment : "androidx.fragment:fragment:$versions.fragmentVersion",
androidxAppcompat : "androidx.appcompat:appcompat:$versions.appcompatVersion",
]

// Project export values

/**
* Parse the project properties for the 'custom_build_mode' property and return
* it for turning on custom build mode.
*/
ext.getCustomBuildMode = { ->
// Retrieve the custom_build_mode from the project property set by the Crossbow build command.
return project.hasProperty("custom_build_mode") ? project.property("custom_build_mode") : false
}

ext.getExportPackageName = { ->
// Retrieve the app id from the project property set by the Crossbow build command.
String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
// Check if the app id is valid, otherwise use the default.
if (appId == null || appId.isEmpty()) {
appId = "com.sergioriebra.multiple_joysticks"
}
return appId
}

ext.getExportVersionCode = { ->
String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
if (versionCode == null || versionCode.isEmpty()) {
versionCode = "1"
}
try {
return Integer.parseInt(versionCode)
} catch (NumberFormatException ignored) {
return 1
}
}

ext.getExportVersionName = { ->
String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
if (versionName == null || versionName.isEmpty()) {
versionName = "1.0"
}
return versionName
}

ext.getExportMinSdkVersion = { ->
String minSdkVersion = project.hasProperty("export_version_min_sdk") ? project.property("export_version_min_sdk") : ""
if (minSdkVersion == null || minSdkVersion.isEmpty()) {
minSdkVersion = "$versions.minSdk"
}
try {
return Integer.parseInt(minSdkVersion)
} catch (NumberFormatException ignored) {
return versions.minSdk
}
}

ext.getExportTargetSdkVersion = { ->
String targetSdkVersion = project.hasProperty("export_version_target_sdk") ? project.property("export_version_target_sdk") : ""
if (targetSdkVersion == null || targetSdkVersion.isEmpty()) {
targetSdkVersion = "$versions.targetSdk"
}
try {
return Integer.parseInt(targetSdkVersion)
} catch (NumberFormatException ignored) {
return versions.targetSdk
}
}
7 changes: 7 additions & 0 deletions examples/multiple_joysticks_mobile/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
android.nonTransitiveRClass=true
export_package_name=com.sergioribera.multiple_joysticks
export_version_code=10
export_version_name=1.0.0
Empty file.
Loading

0 comments on commit 7326153

Please sign in to comment.