Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not invoke A0Auth.showUrl #67

Closed
VERSAYANA opened this issue Jul 25, 2017 · 35 comments · Fixed by #78
Closed

Could not invoke A0Auth.showUrl #67

VERSAYANA opened this issue Jul 25, 2017 · 35 comments · Fixed by #78
Labels
bug This points to a verified bug in the code
Milestone

Comments

@VERSAYANA
Copy link

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",

@jaga-me
Copy link

jaga-me commented Jul 28, 2017

having the same issue

@hzalaz
Copy link
Member

hzalaz commented Jul 30, 2017

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

@VERSAYANA
Copy link
Author

@hzalaz Yes

@ronitslyper
Copy link

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

@0xknon
Copy link

0xknon commented Jul 31, 2017

Same here

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

@hzalaz
Copy link
Member

hzalaz commented Jul 31, 2017

Is this reproducible with our samples?

@ronitslyper
Copy link

@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:+"

@hzalaz
Copy link
Member

hzalaz commented Jul 31, 2017

You can download from https://auth0.com/docs/quickstart/native/react-native

@ronitslyper
Copy link

The sample works fine on the same simulator.

@ronitslyper
Copy link

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?

@michaelspeed
Copy link

yes getting the same issue

@hzalaz
Copy link
Member

hzalaz commented Jul 31, 2017

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

@michaelspeed
Copy link

michaelspeed commented Jul 31, 2017

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'

@hzalaz
Copy link
Member

hzalaz commented Jul 31, 2017

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

@ronitslyper
Copy link

@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 ?

@FredericRuaudel
Copy link

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!

@hzalaz
Copy link
Member

hzalaz commented Aug 6, 2017

@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.

@ronitslyper
Copy link

@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.

@sergeylaptev
Copy link

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

@ronitslyper
Copy link

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).

@hhtu
Copy link

hhtu commented Aug 14, 2017

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

@trondwh
Copy link
Contributor

trondwh commented Aug 16, 2017

@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.

@seanpatrickcatlin
Copy link

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"
                    }
                }
            }
        }
    }
}

@lukewlms
Copy link
Contributor

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

lukewlms pushed a commit to lukewlms/react-native-auth0 that referenced this issue Aug 16, 2017
This change fixes an issue several adopters are running into: "Could not invoke A0Auth.showUrl".  See: auth0#67 (comment)
hzalaz pushed a commit that referenced this issue Aug 18, 2017
This change fixes an issue several adopters are running into: "Could not invoke A0Auth.showUrl".  See: #67 (comment)
@hzalaz hzalaz added this to the v1-Next milestone Aug 18, 2017
@hzalaz hzalaz added the bug This points to a verified bug in the code label Aug 18, 2017
@rodrijuarez
Copy link

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)

@mtt87
Copy link

mtt87 commented Mar 5, 2018

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"
    }
}

@mtt87
Copy link

mtt87 commented Mar 6, 2018

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"
}

@LcTwisk
Copy link

LcTwisk commented Mar 13, 2018

@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.

@mtt87
Copy link

mtt87 commented Mar 13, 2018

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'
    }
}

@lbalmaceda
Copy link
Contributor

@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.

@mtt87
Copy link

mtt87 commented Mar 13, 2018

@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 😄

@sekhuat
Copy link

sekhuat commented May 31, 2018

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

@sinclas
Copy link

sinclas commented Oct 1, 2018

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}"
}

@lbalmaceda
Copy link
Contributor

@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.

@mikebridge
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.