Reputation: 8435
I have project created in android studio and a module in it too.
main project is app module name is jsondb
i want to use jsondb
module as a jar in my main project and even to distribute among the team members.
i have used retrofit , okhttp and other third party library in jsondb
module. so whenever my team member use this jsondb
they don't need to include dependencies related to retrofit or okhttp.
here is my current structure in which i am adding jsondb
as a module. But i want to add it as a jar.
here are the dependencies involved in app
and jsondb
here is my pro-guard settings for jsondb to obfuscate
-keep class com.bluelinelabs.logansquare.** { *; }
-keep @com.bluelinelabs.logansquare.annotation.JsonObject class *
-keep class **$$JsonObjectMapper { *; }
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }
-dontwarn javax.**
-dontwarn io.realm.**
-dontwarn okhttp3.**
-keep class okhttp3.** { *; }
-keep class okhttp3.OkHttpClient.** { *; }
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
-keep public class com.jsondb.db.** { *; }
-keep public class com.jsondb.model.user.** {*; }
-keep public class com.jsondb.model.organization.** {*; }
-keep public class com.jsondb.model.master.** {*; }
-keep public class com.jsondb.model.complaint.** {*; }
-keep public class com.jsondb.db.model.** {*; }
-keep public class com.jsondb.rest.RestApi {*** get*(***); *** callMasterData(***); *** registerRestCallback(***); }
-keep public interface com.jsondb.rest.RestApiCallback {*; }
i tried added aar
file into another project as follows
here you can see i have to add retrofit
and retrofit2 converter
in new project. if i dont add them in gradle then it shows NoClassDefinationFound
for retrofit.
Upvotes: 1
Views: 141
Reputation: 2460
If I understand your question correctly you want to share a module among your different projects.
The common way of doing it is to create an Android Library project. The output is going to be an .aar file which is the jar of the android world :).
Then you just wrap your calls to not call retrofit directly, something like this:
public interface UserWebService {
@POST("customer")
User register(@Body String name);
}
//Wrapper class
public class UserDao{
public User getUser(String name){
//userWebService.register is the actual retrofit call
return userWebService.register(name);
}
}
and in your non library module:
userDao.getUser("Fred")
Some Reference link:
Upvotes: 1