From 29bd835c697ae761083522e2b8e4294a61d89a16 Mon Sep 17 00:00:00 2001 From: Alessandro Grossmann <18agrossmann@gmail.com> Date: Fri, 3 Dec 2021 18:01:38 -0500 Subject: [PATCH] Reconfigured the android Gradle build (#47) * CMakeLists.txt now build jar with ant and gradle package .jar into .aar. Updated README with instructions. * Updated instructions. * Fixed code block formatting. * Replcaing txt with md. * Fixed formatting. * Removed README.TXT. --- android/README.TXT | 20 ------ android/README.md | 61 +++++++++++++++++++ .../gradle/wrapper/gradle-wrapper.properties | 2 +- android/lib/CMakeLists.txt | 7 +++ android/lib/build.gradle | 52 +++++++++++++++- android/local.properties | 10 +++ 6 files changed, 130 insertions(+), 22 deletions(-) delete mode 100644 android/README.TXT create mode 100644 android/README.md create mode 100644 android/local.properties diff --git a/android/README.TXT b/android/README.TXT deleted file mode 100644 index 4d5a342..0000000 --- a/android/README.TXT +++ /dev/null @@ -1,20 +0,0 @@ -This directoy contains Android Studio project files for building the NORM -library for Android. - -TO BUILD: - -./gradlew build - -The lib/build/ directory will contain the binary libraries built. - -The "./gradlew clean" command can be used to delete the files built. - -This directory may also be opened as an Android Studio project and built from -the IDE GUI. - -This will evolve as we update NORM and associated projects to the newer Android -Studio tool chain. - - - - diff --git a/android/README.md b/android/README.md new file mode 100644 index 0000000..40dc7b0 --- /dev/null +++ b/android/README.md @@ -0,0 +1,61 @@ +This directoy contains Android Studio project files for building the NORM +library for Android. + +REQUIREMENTS: + +Ninja is required in order to run the ant build for the java .jar file + +Download and install ndk and cmake using the SDK manager within Android Studio. To do this: + + -> Tools -> SDK Manager -> System Settings -> Android SDK -> SDK Tools -> Select 'Show Package Details' at the bottom + +The latest compatible versions are ndk version 20.0.5594570 and cmake version 3.10.2.4988404 + +* Important * + If you decide to install different version of the SDK Tools above, make sure to edit the path locations in the local.properties file + +TO BUILD: + +./gradlew build + +The lib/build/ directory will contain the binary libraries built. + +The "./gradlew clean" command can be used to delete the files built. + +This directory may also be opened as an Android Studio project and built from +the IDE GUI. + +This will evolve as we update NORM and associated projects to the newer Android +Studio tool chain. + +USAGE: + +Copy the .aar file into your ${project.rootDir}/app/libs/ folder + +Within your app level build.gradle include the following two tasks before your dependencies section: + +``` +task extractSo(type: Copy) { + println 'Extracting *.so file(s)....' + + from zipTree("${project.rootDir}/app/libs/lib-release_-release.aar") + into "${project.rootDir}/app/src/main/jniLibs" + include "jni/**/*.so" + + eachFile { + def segments = it.getRelativePath().getSegments() as List + println segments + it.setPath(segments.tail().join("/")) + return it + } + includeEmptyDirs = false +} + +task extractJar(type: Copy, dependsOn: extractSo) { + println 'Extracting *.jar file(s)....' + + from zipTree("${project.rootDir}/app/libs/lib-release_-release.aar") + into "${project.rootDir}/app/libs/" + include "norm-*.jar" +} +``` diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index d384d28..35b44d8 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1 +1 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip diff --git a/android/lib/CMakeLists.txt b/android/lib/CMakeLists.txt index 24b8f30..9af9a43 100644 --- a/android/lib/CMakeLists.txt +++ b/android/lib/CMakeLists.txt @@ -11,6 +11,13 @@ include_directories( AFTER "../../protolib/include" ) +find_program(ANTPATH ant) + +execute_process( + COMMAND ${ANTPATH} + WORKING_DIRECTORY "$ENV{HOME}/norm/makefiles/java/" +) + enable_language(ASM) IF(BUILD_CONFIGURATION MATCHES "DEBUG") diff --git a/android/lib/build.gradle b/android/lib/build.gradle index 825155d..5aaa45f 100644 --- a/android/lib/build.gradle +++ b/android/lib/build.gradle @@ -21,7 +21,7 @@ android { defaultConfig { externalNativeBuild { cmake { - arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_PLATFORM=android-15", "-DANDROID_STL=c++_static", "-DANDROID_CPP_FEATURES=exceptions rtti", "-DANDROID_ARM_MODE=arm", "-DANDROID_ARM_NEON=TRUE" + arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_PLATFORM=android-15", "-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja", "-DANDROID_STL=c++_static", "-DANDROID_CPP_FEATURES=exceptions rtti", "-DANDROID_ARM_MODE=arm", "-DANDROID_ARM_NEON=TRUE" cFlags "-fsigned-char" cppFlags "-fsigned-char", "-std=c++14" } @@ -91,3 +91,53 @@ dependencies { } +task copyReleaseJar(type: Copy) { + println 'Unzipping release .aar and including .jar....' + + if (file("${project.rootDir}/lib/build/outputs/aar/lib-release_-release.aar").exists()) { + from zipTree("${project.rootDir}/lib/build/outputs/aar/lib-release_-release.aar") + into "${project.rootDir}/lib/build/outputs/aar/lib-release_-release" + + from "${System.env.HOME}/norm/lib/norm-1.0.0.jar" + into "${project.rootDir}/lib/build/outputs/aar/lib-release_-release/" + } +} + +task copyDebugJar(type: Copy, dependsOn: copyReleaseJar) { + println 'Unzipping debug .aar and including .jar....' + + if (file("${project.rootDir}/lib/build/outputs/aar/lib-debug_-debug.aar").exists()){ + from zipTree("${project.rootDir}/lib/build/outputs/aar/lib-debug_-debug.aar") + into "${project.rootDir}/lib/build/outputs/aar/lib-debug_-debug" + + from "${System.env.HOME}/norm/lib/norm-1.0.0.jar" + into "${project.rootDir}/lib/build/outputs/aar/lib-debug_-debug/" + } +} + +task zipReleaseAAR(type: Exec, dependsOn: copyDebugJar) { + println 'Creating new release .aar..' + ignoreExitValue true + workingDir "${project.rootDir}/lib/build/outputs/aar/" + executable 'jar' + def releaseArgsList = ['cvf', 'lib-release_-release.aar', '-C', 'lib-release_-release/', '.'] + args releaseArgsList +} + +task zipDebugAAR(type: Exec, dependsOn: zipReleaseAAR) { + println 'Creating new debug .aar..' + ignoreExitValue true + workingDir "${project.rootDir}/lib/build/outputs/aar/" + executable 'jar' + def debugArgsList = ['cvf', 'lib-debug_-debug.aar', '-C', 'lib-debug_-debug/', '.'] + args debugArgsList +} + +task deleteAARAssets(type: Delete, dependsOn: zipDebugAAR) { + delete "${project.rootDir}/lib/build/outputs/aar/lib-release_-release" + delete "${project.rootDir}/lib/build/outputs/aar/lib-debug_-debug" +} + + +this.build.finalizedBy(deleteAARAssets) + diff --git a/android/local.properties b/android/local.properties new file mode 100644 index 0000000..96385ed --- /dev/null +++ b/android/local.properties @@ -0,0 +1,10 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Sat Nov 13 08:28:03 EST 2021 +sdk.dir=/Users/alessandrogrossmann/Library/Android/sdk +ndk.dir=/Users/alessandrogrossmann/Library/Android/sdk/ndk/20.0.5594570 +cmake.dir=/Users/alessandrogrossmann/Library/Android/sdk/cmake/3.10.2.4988404