Android Studio - App Crashing on AddThis.jar - "Sources Not Found" Message
Asked Answered
B

1

1

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.

Brandy answered 21/9, 2014 at 21:48 Comment(2)
From the documentation, it would appear that the AddThis SDK was written by someone without adequate Android development experience. That being said, it is an Android library project, not a JAR, and so you need to add it as an Android library project.Hiroshige
From the documentation:"The AddThis Android SDK is shipped as a library project, so you can add this to any android project as a library."Heiner
B
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

Brandy answered 22/9, 2014 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.