Unable to start Chrome CustomTabsIntent in my Android app

断了今生、忘了曾经 提交于 2019-12-22 04:46:25

问题


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:


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.




回答2:


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



来源:https://stackoverflow.com/questions/40624768/unable-to-start-chrome-customtabsintent-in-my-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!