1

I'm a total Android newbie here, so hopefully someone can help me out.

I have an Android library (myLib.aar) that I am including/using in the HelloAR demo app. Now, I want to use Instacapture within myLib.aar. I followed the instructions on the README:

dependencies {
    ...
     compile "com.github.tarek360:instacapture:2.0.1"
}

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

I also tried downloading, compiling instacapture source, adding the instacapture.aar to my libs dir and modifying my Gradle files:

dependencies{
    ...
    implementation(name:'instacapture', ext:'aar')
}

allprojects {
   repositories {
       ...
       flatDir {
           dirs 'libs'
       }
}

In both cases, I get the following exception:

    --------- beginning of crash
2020-08-11 22:34:35.965 32761-32761/com.google.ar.core.examples.java.helloar E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.ar.core.examples.java.helloar, PID: 32761
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/tarek360/instacapture/Instacapture;
        at com.cambridge.myLib.ScreenShotter.takeScreenshot(ScreenShotter.java:139)
        at com.google.ar.core.examples.java.helloar.HelloArActivity$2.run(HelloArActivity.java:164)
        at com.google.ar.core.examples.java.helloar.HelloArActivity.startRepeatingTask(HelloArActivity.java:171)
        at com.google.ar.core.examples.java.helloar.HelloArActivity$1.run(HelloArActivity.java:152)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8107)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.tarek360.instacapture.Instacapture" on path: DexPathList[[zip file "/data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/base.apk"],nativeLibraryDirectories=[/data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/lib/arm64, /data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/base.apk!/lib/arm64-v8a, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.cambridge.myLib.ScreenShotter.takeScreenshot(ScreenShotter.java:139) 
        at com.google.ar.core.examples.java.helloar.HelloArActivity$2.run(HelloArActivity.java:164) 
        at com.google.ar.core.examples.java.helloar.HelloArActivity.startRepeatingTask(HelloArActivity.java:171) 
        at com.google.ar.core.examples.java.helloar.HelloArActivity$1.run(HelloArActivity.java:152) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.app.ActivityThread.main(ActivityThread.java:8107) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 

However, if I add the dependencies to the main HelloAR app (as per the instructions in the README), the issue resolves.

Can someone please explain what is going on, why I'm getting the error, and how to resolve it without having to add the dependencies to the main HelloAR app?

pookie
  • 3,796
  • 6
  • 49
  • 105
  • What version of Android Studio are you running? – kabumere Aug 11 '20 at 23:47
  • @kabumere Android Studio 4.0: `Build #AI-193.6911.18.40.6514223, built on May 20, 2020 Runtime version: 1.8.0_242-release-1644-b3-6222593 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o` – pookie Aug 11 '20 at 23:52

1 Answers1

0

Considering your quote,

I'm a total Android newbie here, so hopefully someone can help me out.

Follow these steps (in android studio) :

  1. Go to build menu.
  2. Clean the project by clicking on clean project.
  3. Build the project by clicking on make project.

This process is known as clean build which is usually done after adding some dependencies.

Shreemaan Abhishek
  • 1,134
  • 1
  • 7
  • 33