i18next-react-native-language-detector icon indicating copy to clipboard operation
i18next-react-native-language-detector copied to clipboard

Didn't work on new React-Native App for Android

Open xstable opened this issue 5 years ago • 0 comments
trafficstars

====== ENVIROMENT:

image

======

If I install this Component, the bundling of the App doesn't work for Android. I got the following error:

BUILD FAILED in 6s

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':i18next-react-native-locale-detector'.
> Could not resolve all artifacts for configuration ':i18next-react-native-locale-detector:classpath'.
   > Could not find com.android.tools.build:gradle:3.1.4.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.4/gradle-3.1.4.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :i18next-react-native-locale-detector

Here is my build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.6.2')

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        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()
        maven { url 'https://www.jitpack.io' }
    }
}

STEPS I've tried to fix this

If I go change the build.gradle-file in i18next-react-native-locale-detector and add "google" as repository:

buildscript {
    repositories {
        google() // <-- added this line
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}...

the error-message change to this:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/yourApp/node_modules/i18next-react-native-locale-detector/android/build.gradle' line: 15

* What went wrong:
A problem occurred evaluating project ':i18next-react-native-locale-detector'.
> Could not find method safeExtGet() for arguments [compileSdkVersion, 28] on extension 'android' of type com.android.build.gradle.LibraryExtension.

* 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 ':i18next-react-native-locale-detector'.
> compileSdkVersion is not specified. Please add it to build.gradle

So... ok, we add this missing Method in the file at the very top of react-native-locale-detector's "build.gradle":

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

Now it throw this error:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
....
...
/yourApp/node_modules/i18next-react-native-locale-detector/android/src/main/java/com/i18n/reactnativei18n/ReactNativeI18n.java:23: error: method does not override or implement a method from a supertype
    @Override
    ^
Note: /yourApp/node_modules/i18next-react-native-locale-detector/android/src/main/java/com/i18n/reactnativei18n/ReactNativeI18nLocale.java uses or overrides a deprecated API.
...
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':i18next-react-native-locale-detector:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

xstable avatar Apr 27 '20 10:04 xstable