React-native-auth0: Could not invoke A0Auth.showUrl

Created on 25 Jul 2017  路  35Comments  路  Source: auth0/react-native-auth0

I followed the quick start for react-native.
Now I'm trying to show the login page with
auth0.webAuth .authorize({ scope: 'openid email', audience: 'https://ramtin.auth0.com/userinfo' }) .then(credentials => console.log(credentials)) .catch(error => console.log(error));

But I'm getting "Could not invoke A0Auth.showUrl" error

"react-native": "0.44.0",
"react-native-auth0": "^1.0.3",

bug

Most helpful comment

I ran into this issue previously and concluded that it was due to the fact that launchUrl wasn't added until Android SDK 25 so I assumed that I would need customtabs support library 25 or newer.

To get around this without tweaking files in node_modules I updated the build.gradle in the root of my project to use the customtabs support library 25.0.1 whenever customtabs support library < 25 is being used

I did this by adding the following to my build.gradle file

allprojects {
    configurations.all {
        resolutionStrategy {
            eachDependency { DependencyResolveDetails details ->
                if (details.requested.group == 'com.android.support' && details.requested.name == 'customtabs') {
                    def launchUrlIntoducedVersion = 25
                    def majorVersion = details.requested.version.tokenize('.')[0].toInteger()

                    if (majorVersion < launchUrlIntoducedVersion) {
                        details.useVersion "25.0.1"
                    }
                }
            }
        }
    }
}

All 35 comments

having the same issue

@jaga-me @VERSAYANA did you run react-native link react-native-auth0 as detailed in the README?

@hzalaz Yes

Same issue, working fine on IOS simulator, but getting this error on Android simulator. How can I help debug?

Same here

react-native: 0.43
react-native-auth0: ^1.0.3

Is this reproducible with our samples?

@hzalaz can you point me at the sample to run?

Some more data. From the android debug monitor, the error is this:
screen shot 2017-07-31 at 4 33 00 pm

Did the usual clean, invalidate caches, build, clean, etc.., and changed (oddly) to this:
screen shot 2017-07-31 at 4 42 23 pm

It does seem to be some kind of linking / build tools version error, but I don't see anything out of place. I'm using:
compileSdkVersion 23
buildToolsVersion "23.0.1"
with
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"

The sample works fine on the same simulator.

Tried to make all the versions of packages / tools the same in the sample as in my app - still no crash in the simulator. @hzalaz , any ideas on how to proceed?

yes getting the same issue

@ronitslyper so Auth0 sample worked but in your app didn't?

confirm the sample is working. the package in there is 1.0.1
but its not working on my phone both iOS and Android
android error: could not invoke A0Auth0.showUrl/no virtual method for launchUrl
ios error: its gets to the aprove page. then safari stops. and if you press allow access it shows 'unauthorised'

Unless I can get a repo from you guys that can repro de issue there is little we can do

@hzalaz Yes, the Auth0 sample worked but in my app didn't.

I would be ok sharing my github repo with you. But I've got 9 linked libraries and 40+ npm dependencies - does someone ( @VERSAYANA @jaga-me ) have a more minimal example they could share with @hzalaz ?

I've the same problem too.

The error message is a little misleading in fact because the code where it crashes is this one:

if (activity == null) {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.launchUrl(activity, Uri.parse(url));
} else {
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));
    getReactApplicationContext().startActivity(intent);
}

So we could think that the problem is in the second to last line getReactApplicationContext().startActivity(intent); since the error message is talking about a missing startActivity method. But it's not.

In reality, if we invert the if condition, it kind of fixes the bug. Try replacing the lines above with:

final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
getReactApplicationContext().startActivity(intent);

and the bug is gone.

I've found a stack overflow question that matches this same bugs here

It suggests to bump the support SDK versions to 25.1.0

But as soon as you do this, you got a new error which this time leads to the real function which is launchUrl.

NoSuchMethodError: No virtual method launchUrl

As referred here, this method is available only since API 25.0.0 so it could explain the problem (or not).

Several SDK had this last bug too (Firebase, Spotify and others)

After several tests, I didn't find a way to fix this other than the one above which skip the CustomTabsIntent all together

Anyway, hope these information help solving this issue!

@FredericRuaudel thanks for the info but I think there is something else in play here and I believe its one of the dependencies you added besides react-native-auth0 and to check that I really need a sample where you can repro de issue since I need to debug the dependencies to spot where two clash.

Also ditching CustomTabsIntent is not something I'd do nor recommend since the experience is better than switching to the browser 馃槃 .

@FredericRuaudel @VERSAYANA @jaga-me @ronitslyper @michaelspeed can you at least add to our sample the dependencies you added to your apps one by one till one breaks it? It should only be those that require linking.

@hzalaz I tried doing that in order to create a minimal example with the bug, but couldn't manage to break it! Arrrrrgggh :) . May I share my repo with you? I'll put my contact info in the top-level README and we can continue from there.

I had exactly the same issue, fixed by cleaning gradle files. Strange, react-native-device-info has been unlinked from the project, but still stayed in gradle files (even twice). After this I rebuilt the app and everything works fine. Make sure that all your project dependencies, which require linkage are okay and installed correctly.
image

I finally got this working on android, by looking through all the linked-in libraries in my project, opening their build.gradle, and changing all versions of appcompat-v7 and customtabs to be the same, i.e.
compile "com.android.support:appcompat-v7:23.0.1"
and
compile 'com.android.support:customtabs:23.0.1'
I might have also changed some of the files to have
compileSdkVersion 23
buildToolsVersion "23.0.1"

(gradle pointed in the right direction by warning about mismatches between the versions; I didn't notice these until I started opening the individual build.gradle's).

Hi

I also have this issue, and almost same as @ronitslyper 's method, I change build.gradle file, but instead of changing every linked-in libraries, I only change node_modules/react-native-auth0/android/build.gradle

from

dependencies {
    compile 'com.facebook.react:react-native:+'
    compile 'com.android.support:customtabs:23.3.0'
}

change to

dependencies {
    compile 'com.facebook.react:react-native:+'
    compile 'com.android.support:customtabs:23.0.1'
}

and that's it, I open webauth page successfully, although I don't know why ~ lol

@hzalaz, just wanted to confirm that the small fix by @hhtu works: changing customtabs:23.3.0 to customtabs:23.0.1 in the node_modules/react-native-auth0/android/build.gradle file.

I ran into this issue previously and concluded that it was due to the fact that launchUrl wasn't added until Android SDK 25 so I assumed that I would need customtabs support library 25 or newer.

To get around this without tweaking files in node_modules I updated the build.gradle in the root of my project to use the customtabs support library 25.0.1 whenever customtabs support library < 25 is being used

I did this by adding the following to my build.gradle file

allprojects {
    configurations.all {
        resolutionStrategy {
            eachDependency { DependencyResolveDetails details ->
                if (details.requested.group == 'com.android.support' && details.requested.name == 'customtabs') {
                    def launchUrlIntoducedVersion = 25
                    def majorVersion = details.requested.version.tokenize('.')[0].toInteger()

                    if (majorVersion < launchUrlIntoducedVersion) {
                        details.useVersion "25.0.1"
                    }
                }
            }
        }
    }
}

The @hhtu answer fixed it for me as well. I'll add a suggested pull request.

After implementing the @seanpatrickcatlin solution I started having the following problem:

For faster builds update this project to use the latest build tools.
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
        at com.android.dx.command.dexer.Main.run(Main.java:277)
        at com.android.dx.command.dexer.Main.main(Main.java:245)

I've tried @seanpatrickcatlin solution but it's not working for me.
I still get No virtual method launchUrl(... error.

My build.gradle relevant parts.
Bear in mind I've tried with both 25.0.1 and 26.0.1 which is my target version.

defaultConfig {
        minSdkVersion 24
        targetSdkVersion 26
        multiDexEnabled true
    }
allprojects {
    configurations.all {
        resolutionStrategy {
            eachDependency { DependencyResolveDetails details ->
                if (details.requested.group == 'com.android.support' && details.requested.name == 'customtabs') {
                    def launchUrlIntoducedVersion = 25
                    def majorVersion = details.requested.version.tokenize('.')[0].toInteger()

                    if (majorVersion < launchUrlIntoducedVersion) {
                        details.useVersion "26.0.1"
                    }
                }
            }
        }
    }
}

dependencies {
    compile project(':react-native-fbsdk')
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile project(':react-native-auth0')
    compile project(':bugsnag-react-native')
    compile project(':react-native-vector-icons')
    compile project(':react-native-i18n')
    compile project(':react-native-code-push')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.facebook.react:react-native:+'
    // From node_modules
    compile 'com.google.android.gms:play-services-base:11.6.0'
    compile 'com.google.android.gms:play-services-maps:11.6.0'
    compile 'com.google.android.gms:play-services-location:11.6.0'
    compile 'com.google.android.gms:play-services-gcm:11.6.0'
    compile 'com.google.android.gms:play-services-analytics:11.6.0'
    compile(project(':react-native-onesignal')) {
        exclude group: 'com.google.android.gms'
    }
    compile project(':mapbox-react-native-mapbox-gl')
    compile (project(':react-native-camera')) {
        exclude group: "com.google.android.gms"
    }
    compile (project(':react-native-google-analytics-bridge')) {
        exclude group: "com.google.android.gms"
    }
}

I've managed to solve it first checking the resolved dependencies in my project with
./gradlew androidDependencies

And found out that react-native-auth0 was using com.android.support:customtabs:23.0.1 while FBSDK was using com.android.support:customtabs:27.0.2 so I've hard coded it here /node_modules/react-native-auth0/android/build.gradle

// before
dependencies {
    compile 'com.facebook.react:react-native:+'
    compile "com.android.support:customtabs:${project.ext.buildToolsVersion}"
}
// after
dependencies {
    compile 'com.facebook.react:react-native:+'
    compile "com.android.support:customtabs:27.0.2"
}

@mtt87 this fixed the problem for me as well! I'm using targetSdkVersion 27. Would be nice if we can make it work without tweaking files in node_modules.

I'm not an 馃挬Android 馃挬expert but maybe this could work, I'll try it in my project later

android {
    configurations.all {
        resolutionStrategy.force 'com.android.support:customtabs:27.0.2'
    }
}

@mtt87 @LcTwisk This is a never ending issue... If any of your dependencies decides not to update the support version you'll have the same problem, and every new android version has it's own major version of supports libraries. Depending on what android version you are targeting with your app, you need to match that same major version on the support libraries.

I don't know how to fix this and make everyone happy, if you have a suggestion that doesn't break everyone feel free to post it.

@lbalmaceda I can't think about a solution that works for everyone tbh.

Maybe as a little improvement we can add a section to the README with troubleshooting and mention this issue and copy and paste how to solve it from my post above?

Otherwise let people use the search 馃槃

I also faced the same issue and managed to solve it by @seanpatrickcatlin solution.

I am unclear which one of the above is the appropriate answer. None of them work for me. I keep getting the same issue. Is there a more permanent fix from Auth0? I am completely stuck now. Was working last week, now a dependancy has changed.

This is the gradle for the Aut0 projecT:

project.ext {
buildToolsVersion = "28.0.2"
}

buildscript {
repositories {
jcenter()
}

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

}

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion '28.0.2'

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
lintOptions {
    abortOnError false
}

}

repositories {
mavenCentral()
}

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation "com.android.support:customtabs:${project.ext.buildToolsVersion}"
}

@sinclas

Was working last week, now a dependancy has changed.

What dependency has changed?? We haven't made any new releases for this SDK. If it was working a week before then the issue is not on this SDK.

I got this working by setting supportLibVersion as per this PR. In my case it's 28.0.0 (see also).

Was this page helpful?
0 / 5 - 0 ratings