5

When I build the Amazon (Kindle) flavor of my Android app I run into this Runtime error:

Caused by: java.lang.RuntimeException: Stub!
at com.amazon.device.messaging.ADMMessageReceiver.<init>()

I need the local amazon-device-messaging.jar file to compile my app, however I do not need to include it during runtime as the amazon device will have the necessary classes and methods.

How do I update my Android Studio build.gradle file to do this?

starball
  • 20,030
  • 7
  • 43
  • 238
b.lyte
  • 6,518
  • 4
  • 40
  • 51

3 Answers3

5

To solve this I used the provided type of dependency.

Inside my project modules build.gradle file, right before my dependencies closure I included the following:

configurations {
    provided
}

sourceSets {
    main {
        compileClasspath += configurations.provided
    }
}

And then, within my dependencies closure I included the following:

dependencies {
    provided files('libs/amazon-device-messaging-1.0.1.jar')
}

This ensured that the .jar was only used for compile time and not runtime. I'm quite new to Android Studio, and this took me a while to figure out; hopefully this will help you make the switch to Android Studio as well.

b.lyte
  • 6,518
  • 4
  • 40
  • 51
  • 1
    If the library and the call to the library are in different packages, the 'provided' will be ignored and the stubbed-out library will instead be compiled into the APK anyway. This can be resolved by putting the library in a Maven repo. – Jason Hartley Jul 11 '14 at 15:13
5

I also ran into this issue. When adding the Amazon Device Messaging jar as a library, Android Studio automatically generated

dependencies {
    compile files('libs/amazon-device-messaging-1.0.1.jar')
}

I just needed to switch that to

dependencies {
    provided files('libs/amazon-device-messaging-1.0.1.jar')
}

That did the trick for me. I'd up-vote your answer, @Clu, but I don't have a high enough reputation.

theshadowchild
  • 401
  • 4
  • 6
  • Thanks! Maybe I don't need the additional configurations details. I'll try removing it to see if it still works. – b.lyte Jul 04 '14 at 03:00
  • Looks like your simpler answer is the correct way to do this, thanks! – b.lyte Jul 10 '14 at 01:12
  • I have the ADM jar inside an android-library project, though I have mentioned the dependency of the ADM jar as provided inside the build.grade file of the android-library project. Its am still getting this error. Any help? – sanath01 Feb 20 '15 at 22:59
  • @sanath01 did you ever figure this out. This didn't work for me either? – Jraco11 Aug 16 '16 at 20:43
  • Neither it worked for me guys! Did you find something ? – Fahad-Android Dec 16 '21 at 09:12
1
  1. Add the ADM jar in the Maven local repository.

Command :

            mvn install:install-file "-Dfile=amazon-device-messaging-1.0.1.jar" "-DgroupId=com.amazon.device.messaging" "-DartifactId=amazondevicemessaging" "-Dversion=1.0.1" "-Dpackaging=jar"
  1. Include local maven repository as project dependency :

Add “mavenLocal()” in main Gradle build script:

            allprojects {
            repositories {
                            mavenCentral()
                            mavenLocal()
             }
  1. Link the Maven artifact in ADM project.

Add below line ADMWrapperLib Gradle script (::).

            provided 'com.amazon.device.messaging:amazondevicemessaging:1.0.1'
rajkabbur
  • 187
  • 3