0

I want to create a library (mylib.aar) that gets Android advertise ID.
in base project its needs dependencies like below:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'] )
implementation 'com.android.support:appcompat-v7:25.+'
implementation 'com.google.android.gms:play-services-ads:9.2.1'
}

and it works fine!
the PROBLEM is when i create a release *.aar from the library like the image below and then use the exported mylib.aar in a sample project its not working!

this is how I create the release mylib.aar :

enter image description here

as I said, the new app displays unfortunately has stopped and error it shows me is:

java.lang.NoClassDefFoundError: com.google.android.gms.common.GoogleApiAvailability

how can i solve this?

NOTE: one way is importing *.jar file of the dependency you want and read it from gradle,its working but there is no complete google-play-services.jar for creating AdID

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
amirhosein
  • 844
  • 9
  • 24

1 Answers1

0

If you're creating a library, then you should specify play-services dependencies like this:

dependencies {
    provided 'com.google.android.gms:play-services-ads:15.0.1'
}

provided means you expect the developer that is using your library to also add this dependency.

And it's up to you to handle the cases where this dependency isn't available (wasn't added by the developer using your library).

Also check this: What is the difference between "provided files" and "compile"

Arseny Levin
  • 664
  • 4
  • 10