22
33# Create an AAR with libsodium in all combinations of static | shared | minimal | full.
44#
5- # The x86 static library will not work due to text relocation rules, so static x86 versions are limited to shared libraries.
65# To simplify linking, library variants have distinct names: sodium, sodium-static, sodium-minimal and sodium-minimal-static.
76
87SODIUM_VERSION=" 1.0.20.0"
98NDK_VERSION=$( grep " Pkg.Revision = " < " ${ANDROID_NDK_HOME} /source.properties" | cut -f 2 -d ' =' | cut -f 2 -d' ' | cut -f 1 -d' .' )
109DEST_PATH=$( mktemp -d)
1110
11+ if [ -z " $NDK_PLATFORM " ]; then
12+ export NDK_PLATFORM=" android-21"
13+ echo " Compiling for default platform: [${NDK_PLATFORM} ] - That can be changed by setting an NDK_PLATFORM environment variable."
14+ fi
15+
16+ SDK_VERSION=$( echo " $NDK_PLATFORM " | cut -f2 -d" -" )
17+
1218if which zip > /dev/null; then
1319 echo " The 'zip' command is installed."
1420else
@@ -28,7 +34,7 @@ make_prefab_json() {
2834
2935make_manifest () {
3036 echo " <manifest xmlns:android=\" http://schemas.android.com/apk/res/android\" package=\" com.android.ndk.thirdparty.sodium\" android:versionCode=\" 1\" android:versionName=\" 1.0\" >
31- <uses-sdk android:minSdkVersion=\" 19 \" android:targetSdkVersion=\" 21 \" />
37+ <uses-sdk android:minSdkVersion=\" $SDK_VERSION \" android:targetSdkVersion=\" $SDK_VERSION \" />
3238</manifest>" > " ${1} /AndroidManifest.xml"
3339}
3440
@@ -60,11 +66,6 @@ make_prefab_structure() {
6066 mkdir " $DEST_PATH /${variant} /libs/android.${arch} "
6167 mkdir " $DEST_PATH /${variant} /libs/android.${arch} /include"
6268 NDK_ARCH=" $arch "
63- if [ $arch = " arm64-v8a" ] || [ $arch = " x86_64" ]; then
64- SDK_VERSION=" 21"
65- else
66- SDK_VERSION=" 19"
67- fi
6869
6970 make_abi_json " $DEST_PATH /${variant} /libs/android.${arch} "
7071 done
@@ -118,8 +119,12 @@ zip -9 -r "$AAR_PATH" META-INF prefab AndroidManifest.xml
118119cd .. || exit
119120rm -r " $DEST_PATH "
120121
121- echo
122- echo " Congrats you have built an AAR containing libsodium! To use it with
122+ echo " Congrats you have built an AAR containing libsodium!
123+ The build used a min Android SDK of version $SDK_VERSION
124+ You can build for a different SDK version by specifying NDK_PLATFORM=\" android-{SDK_VERSION}\"
125+ as an environment variable before running this script but the defaults should be fine.
126+
127+ To use the aar with
123128gradle or cmake (as set by default for Android Studio projects):
124129
125130- Edit the app/build.gradle file to add:
0 commit comments