1

我在android studio中創建了項目,並在其中創建了一個模塊。在android studio中使用模塊作爲jar

主要項目是應用 模塊名稱是jsondb

我想用jsondb模塊作爲一個罐子在我的主要項目,甚至到了團隊成員之間的分配。

我在jsondb模塊中使用了翻新,okhttp和其他第三方庫。所以只要我的團隊成員使用jsondb,他們就不需要包含與改造或okhttp相關的依賴關係。

這裏是我當前的結構,其中我將jsondb作爲模塊添加。但是我想把它作爲一個罐子來添加。

current structure app & jsondb

這裏和參與app依賴jsondb

enter image description here

enter image description here

這裏是我的jsondb親衛隊設置混淆

-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 {*; } 

我試圖加入aar文件到另一個項目如下

enter image description here

在這裏你可以看到我有在新項目中添加retrofitretrofit2 converter。如果我不加入他們在gradle那麼它顯示NoClassDefinationFound改造。

+0

下來選民有禮節來解釋原因相同 – Hunt

回答

1

如果我正確理解你的問題,你想在你的不同項目中共享一個模塊。

這樣做的常用方法是創建一個Android庫項目。輸出將是一個.aar文件,它是android世界的jar文件:)。

然後你只需換您的來電不直接調用改造,這樣的事情:

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); 
    } 
} 

和您的非圖書館模塊:

userDao.getUser("Fred") 

一些參考鏈接:

+0

我已審閱本教程只'Vogella' :),我這樣做是相同的,但問題是第三方庫。我已經將它們添加爲'jsondb'中的依賴項,但是當其他團隊成員導入時它仍然會給出'NoClassFound'錯誤 – Hunt

+0

NoClassFound for哪個類? – jbarat

+0

看到我的編輯PLZ – Hunt

相關問題