homeeondemand / react-native-mapbox-navigation

A navigation UI ready to drop into your React Native application
MIT License
153 stars 118 forks source link

Android Build Errors: maven plugin and compileSdkVersion #80

Open nixolas1 opened 2 years ago

nixolas1 commented 2 years ago

Hi, I get two errors when building release 2.0.0 with react native 0.67.3, for android:

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/nixo/projects/elton/node_modules/@homee/react-native-mapbox-navigation/android/build.gradle' line: 26

* What went wrong:
A problem occurred evaluating project ':homee_react-native-mapbox-navigation'.
> Plugin with id 'maven' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':homee_react-native-mapbox-navigation'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

The usage of maven plugin is deprecated, I think.

Oussie00 commented 2 years ago

I'm experiencing the same issue

jamesvovos commented 2 years ago

I found a solution... it seems you're right with the maven plugin deprecation. For now what I've done is used 0.66.1 version of React-Native which uses a downgraded version of Gradle (it fixed it... just make sure you have Java 8 or something set as your path and not Java 17)... Android seems to have problems with it :) Worked for me

soevii commented 2 years ago

Solved without downgrade, this is my build.gradle:

// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
//   original location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
//   original location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

// https://www.cognizantsoftvision.com/blog/creating-an-android-native-module-for-react-native/

def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 19
def DEFAULT_TARGET_SDK_VERSION = 28

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'

buildscript {
    ext.kotlin_version = '1.4.10'
    // The Android Gradle plugin is only required when opening the android folder stand-alone.
    // This avoids unnecessary downloads and potential conflicts when the library is included as a
    // module dependency in an application project.
    // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
    if (project == rootProject) {
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.1'
        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'

android {
    compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
    buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
        targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

repositories {
    // ref: https://www.baeldung.com/maven-local-repository
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        // Android JSC is installed from npm
        url "$rootDir/../node_modules/jsc-android/dist"
    }
    google()
    jcenter()
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules
    implementation 'com.mapbox.navigation:core:1.5.0'
    implementation 'com.mapbox.navigation:ui:1.5.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

def configureReactNativePom(def pom) {
    def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

    pom.project {
        name packageJson.title
        artifactId packageJson.name
        version = packageJson.version
        group = "com.homee.mapboxnavigation"
        description packageJson.description
        url packageJson.repository.baseUrl

        licenses {
            license {
                name packageJson.license
                url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
                distribution 'repo'
            }
        }
    }
}

afterEvaluate { project ->
    android.libraryVariants.all { variant ->
        def name = variant.name.capitalize()
        def javaCompileTask = variant.javaCompileProvider.get()

        task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
            from javaCompileTask.destinationDir
        }
    }
}
ayuleul commented 2 years ago

This is due to Gradle 7 removed the maven plugin. This issue will occur if you use gradle 7 in your project. I fixed the problem by downgrading to Gradle 6.9.

The gradle version can be found in android/gradle/wrapper/gradle-wrapper.properties

OleTheDev commented 2 years ago

I solved this by going into "\node_modules\@homee\react-native-mapbox-navigation\android" and replacing build.gradle with this:

// android/build.gradle

// based on: // // https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle // original location: // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle // // https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle // original location: // - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

// https://www.cognizantsoftvision.com/blog/creating-an-android-native-module-for-react-native/

def DEFAULT_COMPILE_SDK_VERSION = 28 def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3' def DEFAULT_MIN_SDK_VERSION = 19 def DEFAULT_TARGET_SDK_VERSION = 28

def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback }

apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'maven-publish'

buildscript { ext.kotlin_version = '1.4.10' // The Android Gradle plugin is only required when opening the android folder stand-alone. // This avoids unnecessary downloads and potential conflicts when the library is included as a // module dependency in an application project. // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies if (project == rootProject) { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.4.1' } }

repositories {
    mavenCentral()
}

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

}

apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'maven-publish'

android { compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) defaultConfig { minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) versionCode 1 versionName "1.0" } lintOptions { abortOnError false } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = "1.8" } }

repositories { // ref: https://www.baeldung.com/maven-local-repository mavenLocal() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } maven { // Android JSC is installed from npm url "$rootDir/../node_modules/jsc-android/dist" } google() jcenter() }

dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' // From node_modules implementation 'com.mapbox.navigation:core:1.5.0' implementation 'com.mapbox.navigation:ui:1.5.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }

def configureReactNativePom(def pom) { def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

pom.project {
    name packageJson.title
    artifactId packageJson.name
    version = packageJson.version
    group = "com.homee.mapboxnavigation"
    description packageJson.description
    url packageJson.repository.baseUrl

    licenses {
        license {
            name packageJson.license
            url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
            distribution 'repo'
        }
    }
}

}

task androidSourcesJar(type: Jar) { classifier = 'sources' from android.sourceSets.main.java.srcDirs }

afterEvaluate { publishing { publications { release(MavenPublication) { from components.release // Add additional sourcesJar to artifacts artifact(androidSourcesJar) } } repositories { maven { url = mavenLocal().url } } } }

jamesvovos commented 1 year ago

When I try to do add your code to the build.graddle file in the node modules I get this error "Task :homee_react-native-mapbox-navigation:compileDebugKotlin FAILED"

adhendo commented 1 year ago

Hi @OleTheDev your patch worked but had the same issue as @jamesvovos, updating the kotlin version to 1.6.0 in the @home/react-native-mapbox-navigation build.gradle worked to fix it! thanks for the help!