gpt4 book ai didi

android - 在 android studio 中将模块用作 jar

转载 作者:行者123 更新时间:2023-11-30 01:29:04 25 4
gpt4 key购买 nike

我在 android studio 中创建了一个项目,其中也有一个模块。

主要项目是app模块名称是 jsondb

我想在我的主项目中使用 jsondb 模块作为 jar,甚至分发给团队成员。

我在 jsondb 模块中使用了 retrofit 、 okhttp 和其他第三方库。因此,每当我的团队成员使用此 jsondb 时,他们都不需要包含与 retrofit 或 okhttp 相关的依赖项。

这是我当前的结构,我将 jsondb 添加为一个模块。但我想将它添加为一个 jar 。

current structure app & jsondb

这里是appjsondb涉及的依赖

enter image description here

enter image description here

这是我对 jsondb 进行混淆的 pro-guard 设置

-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 以进行改造。

最佳答案

如果我正确理解你的问题,你想在你的不同项目之间共享一个模块。

通常的做法是创建一个 Android Library 项目。输出将是一个 .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")

一些引用链接:

关于android - 在 android studio 中将模块用作 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36014677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com