Skip to content

Commit

Permalink
feat: upgrade gradle setup
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian committed Dec 6, 2024
1 parent b86bd63 commit 21442a6
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 74 deletions.
9 changes: 0 additions & 9 deletions android/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions android/.npmignore

This file was deleted.

148 changes: 97 additions & 51 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,69 +1,115 @@
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.2"
// 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()
}
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()
}

static 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")
}
7 changes: 7 additions & 0 deletions android/gradle.properties
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
6 changes: 4 additions & 2 deletions android/src/main/AndroidManifest.xml
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>
5 changes: 5 additions & 0 deletions android/src/main/AndroidManifestNew.xml
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>
3 changes: 0 additions & 3 deletions android/src/main/res/values/strings.xml

This file was deleted.

0 comments on commit 21442a6

Please sign in to comment.