urbanairship / react-native-airship

Airship React Native module
Other
88 stars 62 forks source link

Android installation fails #84

Closed mixophrygian closed 6 years ago

mixophrygian commented 6 years ago

Heyo, running into some issues linking the UA library to my Android Manifest.

React-native-cli: 2.0.1 react-native: 0.53.3 node: v8.0.0 urbanairship-react-native: 1.4.2

I'm following the installation guide to a T, here are the tasks I suspect aren't quiet completing:

  1. Running react-native link urbanairship-react-native produces an Unhandled Promise Rejection Warning with "Error no such file or directory, open "/Users/me/Desktop/ourproj/android/app/src/main/java/com/teamname/projectname/MainApplication.java"

In fact that file doesn't exist...but /Users/me/Desktop/ourproj/android/app/src/main/java/com/projectname/MainApplication.java does. Note the missing /teamname/

As a result MainApplication.java doesn't get updated... I did manually update this file to import com.urbanairship.reactnative.ReactAirshipPackage; and include new ReactAirshipPackage() in my packages array, though this didn't get me any further, possibly due to the following error:

  1. Attempting to run react-native run-android after that results in
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApk'.
   > A problem occurred configuring project ':urbanairship-react-native'.
      > Could not resolve all dependencies for configuration ':urbanairship-reac
-native:_debugPublishCopy'.
         > Could not find any version that matches com.google.android.gms:play-s
rvices-gcm:[11.8.0,).
           Versions that do not match:
               11.0.4
               11.0.2
               11.0.1
               11.0.0
               10.2.6
               + 18 more
              Searched in the following locations:
               file:/Users/me/Library/Android/sdk/extras/google/m2repo
sitory/com/google/android/gms/play-services-gcm/maven-metadata.xml
               file:/Users/me/Desktop/our-project/android/sdk-manager/
com/google/android/gms/play-services-gcm/maven-metadata.xml
               file:/Users/me/Desktop/our-project/android/sdk-manager/
com/google/android/gms/play-services-gcm/
               file:/Users/me/Library/Android/sdk/extras/android/m2rep
ository/com/google/android/gms/play-services-gcm/maven-metadata.xml
               file:/Users/me/Library/Android/sdk/extras/android/m2rep
ository/com/google/android/gms/play-services-gcm/
               file:/Users/me/Desktop/our-project/android/sdk-manager/
com/google/android/gms/play-services-gcm/maven-metadata.xml
               file:/Users/me/Desktop/our-project/android/sdk-manager/
com/google/android/gms/play-services-gcm/
           Required by:
               Authenticator:urbanairship-react-native:unspecified

Looks like it wants google play services but can't find it. So in my android/app/build.gradle I include the following dependencies:

dependencies {
   ...
    compile project(':urbanairship-react-native')
    compile 'com.google.android.gms:play-services-gcm:+'

Doesn't seem to have an effect. (Before running I installed the Google Play Services through the SDK Manager of Android Studio, version 46)

Other possibly relevant info in my app level build.gradle:

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 24
        ...
    }

And the top level build.gralde:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    configurations.all {
        resolutionStrategy {
            eachDependency { DependencyResolveDetails details ->
                if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
                    details.useVersion "0.53.3"
                }
            }
        }
    }
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

Is this funkiness with the maven reference, do you think? Thanks.

crow commented 6 years ago

@mixophrygian What happens when you attempt to run your android project directly from your IDE? You might get a clearer picture of what's happening from attempting to run from the IDE instead of run-android command - especially if it's some kind of dependency issue.

rlepinski commented 6 years ago

@mixophrygian You need to add google's maven repo to your repositories

allprojects {
    repositories {
        google()

        // If you're using a version of Gradle lower than 4.1, you must instead use:
        // maven {
        //     url 'https://maven.google.com'
        // }
        // An alternative URL is 'https://dl.google.com/dl/android/maven2/'
    }
}
mixophrygian commented 6 years ago

@rlepinski nailed it! TIL build.gradle can use multiple mavens. Here's where I landed in my react-native project to support this package as well as the new react-native-camera:

android/build.gradle

repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }