我正在尝试将我的应用程序中的照片分享到Facebook。我添加了Facebook SDK并完成了初始设置。但是当我运行应用程序时崩溃,我得到以下异常。
这是我的logcat:
java.lang.RuntimeException: Unable to get provider com.facebook.internal.FacebookInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.facebook.internal.FacebookInitProvider" on path: DexPathList[[zip file "/data/app/com.ignite.a01hw909350.kolamdemo-2/base.apk", zip file "/data/app/com.ignite.a01hw909350.kolamdemo-2/split_lib_slice_1_apk.apk"],nativeLibraryDirectories=[/data/app/com.ignite.a01hw909350.kolamdemo-2/lib/arm64, /data/app/com.ignite.a01hw909350.kolamdemo-2/base.apk!/lib/arm64-v8a, /data/app/com.ignite.a01hw909350.kolamdemo-2/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5267)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4859)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4799)
at android.app.ActivityThread.access$1600(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1434)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5609)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.internal.FacebookInitProvider" on path: DexPathList[[zip file "/data/app/com.ignite.a01hw909350.kolamdemo-2/base.apk", zip file "/data/app/com.ignite.a01hw909350.kolamdemo-2/split_lib_slice_1_apk.apk"],nativeLibraryDirectories=[/data/app/com.ignite.a01hw909350.kolamdemo-2/lib/arm64, /data/app/com.ignite.a01hw909350.kolamdemo-2/base.apk!/lib/arm64-v8a, /data/app/com.ignite.a01hw909350.kolamdemo-2/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.ActivityThread.installProvider(ActivityThread.java:5252)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4859)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4799)
at android.app.ActivityThread.access$1600(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1434)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5609)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Suppressed: java.lang.ClassNotFoundException: com.facebook.internal.FacebookInitProvider
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
这是我的Manifest.xml
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity android:name=".MainActivity" />
<activity
android:name=".ARCameraActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="fullSensor" />
<activity
android:name=".RegistrationActivity"
android:screenOrientation="portrait" />
<activity
android:name=".LoginActivity"
android:screenOrientation="portrait" />
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MenuActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ScanAndDrawActivity"
android:screenOrientation="portrait" />
<activity
android:name=".GalleryActivity"
android:screenOrientation="portrait" />
<activity
android:name=".PdfKolamActivity"
android:screenOrientation="portrait" />
<service
android:name=".BluetoothService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.ignite.a01hw909350.kolamdemo.BluetoothService" />
</intent-filter>
</service>
<receiver
android:name=".MyScheduleReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>
<activity
android:name=".BotDialogActivity"
android:launchMode="singleInstance"
android:noHistory="true"
android:theme="@style/Theme.AppCompat.Light.Translucent" />
<activity android:name=".ModelActivity" />
<activity android:name=".PanchangActivity" />
<receiver
android:name=".MyStartServiceReceiver" android:exported="true"/>
<service
android:name=".services.AlarmService"
android:enabled="true">
<intent-filter>
<action android:name="NOTIFICATION_SERVICE" />
</intent-filter>
</service>
<receiver
android:name=".BootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<provider android:authorities="com.facebook.app.FacebookContentProvider43234236033829"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
</application>
这是我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.ignite.a01hw909350.kolamdemo"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
noCompress 'KARMarker'
noCompress 'armodel'
}
repositories {
jcenter()
maven()
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':KudanAR1')
compile project(':eventbus-3.0.0')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.scottyab:secure-preferences-lib:0.1.4'
compile 'com.jrummyapps:animated-svg-view:1.0.1'
compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
compile 'io.palaima:smoothbluetooth:0.1.0'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.afollestad.material-dialogs:core:0.9.3.0'
compile 'com.flurgle:camerakit:0.9.13'
compile 'com.github.zhukic:sectioned-recyclerview:1.0.0'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.prolificinteractive:material-calendarview:1.4.3'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:design:25.3.1'
compile 'com.github.barteksc:android-pdf-viewer:2.4.0'
compile 'org.rajawali3d:rajawali:1.1.668@aar'
compile 'com.tapadoo.android:alerter:1.0.8'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'uk.co.chrisjenx:calligraphy:2.3.0'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
testCompile 'junit:junit:4.12'
}
问题出在哪里?
答案 0 :(得分:5)
我遇到了同样的错误,因为设置错误multidex。 Android 4.4.2设备上出现此问题。
这是我在build.gradle:
REMOVE
我必须添加到build.gradle:
defaultConfig {
multiDexEnabled true
}
这个方法到我的应用程序类:
dependencies {
compile 'com.android.support:multidex:1.0.2'
}
答案最初来自here,当我通过删除facebook SDK避免facebook问题时我必须解决这个问题。所以也许可以从那里帮助另一个提示。
答案 1 :(得分:2)
尝试将您的facebook-sdk版本更改为最新版本(现在为4.24.0):
compile 'com.facebook.android:facebook-android-sdk:4.24.0'
答案 2 :(得分:0)
更新您的Google Play服务 11.0.2
compile 'com.google.android.gms:play-services-maps:11.0.2'
compile 'com.google.android.gms:play-services-location:11.0.2'
这解决了这个问题。
答案 3 :(得分:0)
确保gradle不在离线工作模式下运行,否则它将不会从存储库下载sdk。
通过以下步骤使Gradle联机工作: 1-通过单击文件>设置打开“首选项”窗口 2-在左侧窗格中,单击生成,执行,部署> Gradle 3-取消选中“离线工作”复选框 4-单击确定
答案 4 :(得分:0)
只需尝试清理项目并重建项目。