问题
I have a project using the AddThis SDK. I have added the AddThis.jar as a library to my project in Android Studio.
When I tap the button to Post to Facebook, the app crashes with this log:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apploi/com.addthis.ui.activities.ATActivityGroup}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apploi/com.addthis.ui.activities.ATShareActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apploi/com.addthis.ui.activities.ATShareActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2035)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at com.addthis.ui.activities.ATActivityGroup.showNextView(ATActivityGroup.java:167)
at com.addthis.ui.activities.ATActivityGroup.loadViews(ATActivityGroup.java:99)
at com.addthis.ui.activities.ATActivityGroup.onCreate(ATActivityGroup.java:78)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1123)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
at android.content.res.Resources.getLayout(Resources.java:939)
at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.addthis.ui.activities.ATShareActivity.onCreate(ATShareActivity.java:66)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2035)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at com.addthis.ui.activities.ATActivityGroup.showNextView(ATActivityGroup.java:167)
at com.addthis.ui.activities.ATActivityGroup.loadViews(ATActivityGroup.java:99)
at com.addthis.ui.activities.ATActivityGroup.onCreate(ATActivityGroup.java:78)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Connection reset by peer
From what I can tell, this line is saying that the ATShareActivity is having problems.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apploi/com.addthis.ui.activities.ATShareActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
When I navigate into AddThis.jar
and open the ATShareActivity
file (or any other file inside the jar file), a message appears at the top of the screen saying "Sources Not Found", with a clickable link titled Attach Sources...
I open the Attach Sources...
link and it allows me to select a directory, but I don't know what I am supposed to do here.
Any ideas about this would be greatly appreciated.
回答1:
Thank you for the tips. Here's what ended up finally working:
1) Convert AddThis to Gradle
File > Import Project...
to transition AddThisSDK
to a Gradle Project. This created a new project, which I named AddThisGradle
1B) If You Already have the Facebook SDK Installed
Opened Terminal and navigated inside the new AddThisGradle
directory to AddThisGradle/app/libs
Used command zip -d addthis0.0.8.jar com/facebook/*
in Terminal to delete the Facebook files from addthis0.0.8.jar
Went back to Android Studio
, checked that the Facebook directory disappeared from AddThisGradle
Went back to my my main project in Android Studio
2) Add AddThis to Your Project
Selected File > Project Structure
in my main project in Android Studio
Pressed the +
in the upper-left of the Project Structure screen.
The New Module
screen appears
Selected Import Existing Project
in the New Module
screen
Selected AddThisGradle
as the source directory
Checked the import
checkbox
Changed the module name
to :addthis
Click the Finish
button
Wait for gradle to re-sync
3) Add Dependency
Back to the Project Structure
screen
Select app
in the left column of the Project Structure
screen
Select the Dependencies
tab
Click the +
button at the bottom of the Dependencies
tab screen
Select + > 3 Module Dependency
The Choose Module
screen appears
Select the :addthis
Module
Wait for gradle to re-sync
4) Keep Trying
At this point, everything seemed good except when I tried to run the app I was getting an error that said Execution failed for task ':app:dexDebug’
. I used the first suggestion from this question to fix my problem: Gradle Execution failed for task ':app:dexDebug' with new Android Studio Project
来源:https://stackoverflow.com/questions/25964223/android-studio-app-crashing-on-addthis-jar-sources-not-found-message