diff --git a/android/.gitignore b/android/.gitignore deleted file mode 100644 index 39fb081a4..000000000 --- a/android/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures -.externalNativeBuild diff --git a/android/.npmignore b/android/.npmignore deleted file mode 100644 index 39fb081a4..000000000 --- a/android/.npmignore +++ /dev/null @@ -1,9 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures -.externalNativeBuild diff --git a/android/build.gradle b/android/build.gradle index 0b4e8cef4..41abb73fe 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,69 +1,116 @@ -apply plugin: 'com.android.library' +buildscript { + // Buildscript is evaluated before everything else so we can't use getExtOrDefault + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["MapLibreReactNative_kotlinVersion"] + + repositories { + google() + mavenCentral() + } + + dependencies { + classpath "com.android.tools.build:gradle:7.2.1" + // noinspection DifferentKotlinGradleVersion + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} -def safeExtGet(prop, fallback) { - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback +def reactNativeArchitectures() { + def value = rootProject.getProperties().get("reactNativeArchitectures") + return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] } def isNewArchitectureEnabled() { - return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" } -buildscript { - ext { - buildToolsVersion = "33.0.0" - minSdkVersion = 16 - compileSdkVersion = 34 - targetSdkVersion = 33 - supportLibVersion = "28.0.0" - } +apply plugin: "com.android.library" +apply plugin: "kotlin-android" - repositories { - google() - mavenCentral() - } +// TODO: Currently breaks new arch support, but works without +// if (isNewArchitectureEnabled()) { +// apply plugin: "com.facebook.react" +// } + +def getExtOrDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["MapLibreReactNative_" + name] +} + +def getExtOrIntegerDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["MapLibreReactNative_" + name]).toInteger() +} + +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 } android { - compileSdkVersion safeExtGet("compileSdkVersion", 33) - buildToolsVersion safeExtGet("buildToolsVersion", '33.0.1') - - defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', 16) - targetSdkVersion safeExtGet('targetSdkVersion', 26) - versionCode 1 - versionName "1.0" - buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) - } + if (supportsNamespace()) { + namespace "org.maplibre.reactnative" - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } } + } + + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") + + defaultConfig { + minSdkVersion getExtOrIntegerDefault("minSdkVersion") + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") - buildTypes { - release { - minifyEnabled false - } + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() + } + + buildTypes { + release { + minifyEnabled false } + } + + lintOptions { + disable "GradleCompatible" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } +repositories { + mavenCentral() + google() +} + +def kotlin_version = getExtOrDefault("kotlinVersion") + dependencies { - // The version of react-native is set by the React Native Gradle Plugin - implementation("com.facebook.react:react-android") - - // MapLibre SDK - implementation "org.maplibre.gl:android-sdk:11.5.0" - implementation "org.maplibre.gl:android-sdk-turf:6.0.1" - - // Dependencies - implementation "androidx.vectordrawable:vectordrawable:1.1.0" - implementation "androidx.annotation:annotation:1.7.0" - implementation "androidx.appcompat:appcompat:1.6.1" - implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttpVersion', '4.9.0')}" - implementation "com.squareup.okhttp3:okhttp-urlconnection:${safeExtGet('okhttpVersion', '4.9.0')}" - - // MapLibre plugins - implementation ("org.maplibre.gl:android-plugin-localization-v9:3.0.1") - implementation ("org.maplibre.gl:android-plugin-annotation-v9:3.0.1") - implementation ("org.maplibre.gl:android-plugin-markerview-v9:3.0.1") + // For < 0.71, this will be from the local maven repo + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin + //noinspection GradleDynamicVersion + implementation "com.facebook.react:react-native:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + // MapLibre SDK + implementation "org.maplibre.gl:android-sdk:11.5.0" + implementation "org.maplibre.gl:android-sdk-turf:6.0.1" + + // Dependencies + implementation "androidx.vectordrawable:vectordrawable:1.1.0" + implementation "androidx.annotation:annotation:1.7.0" + implementation "androidx.appcompat:appcompat:1.6.1" + implementation "com.squareup.okhttp3:okhttp:${getExtOrDefault('okhttpVersion')}" + implementation "com.squareup.okhttp3:okhttp-urlconnection:${getExtOrDefault('okhttpVersion')}" + + // MapLibre plugins + implementation ("org.maplibre.gl:android-plugin-localization-v9:3.0.1") + implementation ("org.maplibre.gl:android-plugin-annotation-v9:3.0.1") + implementation ("org.maplibre.gl:android-plugin-markerview-v9:3.0.1") } diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 000000000..7989274b6 --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,7 @@ +MapLibreReactNative_kotlinVersion=1.7.0 +MapLibreReactNative_minSdkVersion=21 +MapLibreReactNative_targetSdkVersion=31 +MapLibreReactNative_compileSdkVersion=31 +MapLibreReactNative_ndkversion=21.4.7075529 + +MapLibreReactNative_okhttpVersion=4.9.0 diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 605879763..831543d99 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,4 +1,6 @@ - + + - + diff --git a/android/src/main/AndroidManifestNew.xml b/android/src/main/AndroidManifestNew.xml new file mode 100644 index 000000000..ee204a9d4 --- /dev/null +++ b/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml deleted file mode 100644 index a60874842..000000000 --- a/android/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - MLRN -