8

I am trying to use Chrome Custom Tabs in my Android application. My MainActivity class extends AppCompatActivity. In onCreate, I invoke startCustomTabs. Below is the code for that:

private void startCustomTab(){ CustomTabsIntent intent = new CustomTabsIntent.Builder().setToolbarColor(getResources().getColor(R.color.colorPrimary)).build(); intent.launchUrl(this, Uri.parse("http://github.com/black-dragon/SaavnExtractor")); } 

As soon as the app launches, it crashes with following the error:

11-16 10:55:38.561 30093-30093/com.nick.saavnextractor E/AndroidRuntime: FATAL EXCEPTION: main Process: com.nick.saavnextractor, PID: 30093 java.lang.NoSuchMethodError: No static method startActivity(Landroid/app/Activity;Landroid/content/Intent;Landroid/os/Bundle;)V in class Landroid/support/v4/app/ActivityCompat; or its super classes (declaration of 'android.support.v4.app.ActivityCompat' appears in /data/data/com.nick.saavnextractor/files/instant-run/dex/slice-com.android.support-support-compat-25.0.0_15c83dd4ec129d2d74bfda2e34f6aeeb93d83fa1-classes.dex) at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:262) at com.nick.saavnextractor.MainActivity.startCustomTab(MainActivity.java:325) at com.nick.saavnextractor.MainActivity.onCreate(MainActivity.java:111) at android.app.Activity.performCreate(Activity.java:6311) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2539) at android.app.ActivityThread.access$900(ActivityThread.java:159) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1384) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5507) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Note: If I execute the same code with the same methods in a new app, the Custom Tabs launch fine.

1
  • What build tools version are you using? Commented Nov 17, 2016 at 14:17

3 Answers 3

11

Okay, so here is the resolution. I was using build tools version 25.0.0 but my SDK platform was 24.

Update the build tools, platform tools & SDK to same version and then you won't face this issue.

Sign up to request clarification or add additional context in comments.

2 Comments

Found a solution to my problem. I had to make sure to import the dependency corresponding to the SDK version I'm compiling with. Customtabs website's implementation guide has version 23.3.0 of the dependency. I had to change that to 25.0.1
There's even a warning in gradle about having incompatible versions, can't believe I missed this.
3

Along with @Nick's answer, I also had to update the Facebook SDK version and the crash stopped happening.

1 Comment

This was it for me. Was using 4.16.1 but upgraded to 4.20.0 and worked.
0

You need to add Customtabs dependency in your build.gradle file.

implementation 'com.android.support:customtabs:28.0.0' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.