-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade Android gradle setup (#539)
- Loading branch information
1 parent
d08cb48
commit 761ae0d
Showing
7 changed files
with
114 additions
and
74 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.maplibre.reactnative"> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.maplibre.reactnative"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
</manifest> |
This file was deleted.
Oops, something went wrong.