2017-01-10 96 views
2

我想用我的应用程序使用chrome自定义选项卡连接fitbit。但我得到以下错误。Chrome CustomTab错误:java.lang.NoSuchMethodError:没有静态方法startActivity

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.life.myApp.app/files/instant-run/dex/slice-com.android.support-support-compat-25.0.1_a32c44837a06d33159cc113605aa7f1cb8d56675-classes.dex) at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:200) at com.life.myApp.app.ThirdPartyLibrary.TrackersDevies.FitBitTracker.LoginFitTrackers.onActivityCreated(LoginFitTrackers.java:208) at android.app.Fragment.performActivityCreated(Fragment.java:2289) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1008) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1164) at android.app.BackStackRecord.run(BackStackRecord.java:793) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1557) at android.app.FragmentManagerImpl$1.run(FragmentManager.java:488) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7223) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

这里是我的gradle这个文件

buildscript { 
repositories { 
    maven { url 'https://maven.fabric.io/public' } 
} 

dependencies { 
    classpath 'io.fabric.tools:gradle:1.+' 
} 
} 
apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 
android { 
compileSdkVersion 24 
buildToolsVersion '24.0.1' 

dexOptions { 
    javaMaxHeapSize "4g" 
    incremental = true; 

} 

defaultConfig { 
    applicationId "com.life.myApp.app" 
    minSdkVersion 16 
    targetSdkVersion 24 
    versionCode 20 
    versionName "1.1.0.15" 
    multiDexEnabled true 
} 
compileOptions { 
    sourceCompatibility = JavaVersion.VERSION_1_7 
    targetCompatibility = JavaVersion.VERSION_1_7 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
allprojects { 
    tasks.withType(JavaCompile) { 
     options.compilerArgs << "-Xlint:deprecation" 
    } 
} 
} 

repositories { 
maven { url 'https://maven.fabric.io/public' } 
} 


dependencies { 
compile 'com.android.support:customtabs:24.2.1' 
compile 'com.android.support:appcompat-v7:24.2.1' 
compile 'com.android.support:design:24.2.1' 
compile 'com.android.support:support-v4:24.2.1' 
compile 'com.android.support:multidex:1.0.1' 
compile 'com.google.android.gms:play-services-analytics:9.6.1' 
compile 'com.adjust.sdk:adjust-android:4.7.0' 
compile 'com.segment.analytics.android:analytics:4.2.0' 
compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
    transitive = true; 
} 
compile 'oauth.signpost:signpost-core:1.2.1.2' 
compile 'oauth.signpost:signpost-commonshttp4:1.2.1.2' 
compile 'com.squareup.picasso:picasso:2.4.0' 
compile 'com.google.android.gms:play-services-fitness:9.6.1' 
compile 'com.google.android.gms:play-services-auth:9.6.1' 
compile 'com.google.code.gson:gson:2.7' 
compile 'com.android.support:cardview-v7:24.2.1' 
compile 'com.mcxiaoke.volley:library-aar:1.0.0' 
compile 'com.liulishuo.magicprogresswidget:library:1.0.9' 
compile 'com.wdullaer:materialdatetimepicker:3.0.0' 

} 

configurations { 
compile.exclude group: "org.apache.httpcomponents", module: "httpclient" 
} 
/* 
android { 
useLibrary 'org.apache.http.legacy' 
}*/ 

这是我的Java代码。

speedUpChromeTabs(); 
     weakReference = new WeakReference<Activity>(getActivity()); 

     CustomTabsClient.bindCustomTabsService(getActivity().getApplicationContext(), CUSTOM_TAB_PACKAGE_NAME, mCustomTabsServiceConnection); 
     customTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession) 
       .setToolbarColor(ContextCompat.getColor(getActivity(), R.color.blue)) 
       .setShowTitle(true) 
       .build(); 
    url = url + "?time=" + (new Date().getTime()); 
       customTabsIntent.launchUrl(getActivity(), Uri.parse("http://www.google.com")); 

我已经试过ThisThisThis但没有成功为止。

+0

添加java代码也是 – W4R10CK

+0

错误提示'没有静态方法startActivity(Landroid/app/Activity; Landroid/content/Intent; Landroid/os/Bundle; )V类的Landroid/support/v4/app/ActivityCompat;或者它的超类“,可能错误在于活动。 – W4R10CK

+0

Hi @ W4R10CK感谢您的回复。你能详细解释我吗? –

回答

2

我更新了我的应用程序中的代码并完美地工作。

mCustomTabsServiceConnection = new CustomTabsServiceConnection() { 
      @Override 
      public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) { 
       mCustomTabsClient= customTabsClient; 
       mCustomTabsClient.warmup(0L); 
       mCustomTabsSession = mCustomTabsClient.newSession(null); 
      } 

      @Override 
      public void onServiceDisconnected(ComponentName name) { 
       mCustomTabsClient= null; 
      } 
     }; 

     CustomTabsClient.bindCustomTabsService(getActivity(), CUSTOM_TAB_PACKAGE_NAME, mCustomTabsServiceConnection); 

     mCustomTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession) 
       .setShowTitle(true) 
       .build(); 

android { 
    compileSdkVersion 25 
    buildToolsVersion '25.0.1' 

    defaultConfig { 
     applicationId "com.MyApp.app" 
     minSdkVersion 16 
     targetSdkVersion 25 
     multiDexEnabled true 
    } 

compile 'com.android.support:appcompat-v7:25.1.0' 
    compile 'com.android.support:design:25.1.0' 

    compile 'com.android.support:customtabs:25.1.0+' 
    compile 'com.android.support:design:25.1.0' 
    compile 'com.android.support:support-v4:25.1.0' 
0

我已经使用在一个项目

compileSdkVersion 25 
buildToolsVersion '25.0.1' 

但项目设置SDK版本低于我在哪里使用Chrome自定义选项卡,并获得在gradle这个文件改变同样的例外

compileSdkVersion 24 
buildToolsVersion '24.0.0' 

请将编译和目标sdk版本从24更新到25

相关问题