Android Studio 3.4.2
Android Studio 3.4.2
我有使用模块 mytransport 的主项目(应用程序),如下所示:
I has main project (app) that use module mytransport like this:
app/build.gradle
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { transitive = true; }
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation project(':mytransport')
}
在 mytransport/build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
}
在 mytransport
代码中,我成功使用了这样的代码:
In mytransport
code I success use code like this:
在 MyProjectmytransportsrcmainjavacommycompanyandroidmytransportutilMyUtil.java
片段:
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
public class JSONUtil {
private static GsonBuilder gsonbuilder = new GsonBuilder();
不错.
现在我想在主应用程序中使用 gson 库.所以在主应用程序我试试这个
Now I want in main app to use gson lib. So in main app I try this in
MyProjectandroidMyProjectappsrcmainjavacommycompanyandroidmyprojectmainMainApp.java
片段
import android.app.Application;
import android.content.Context;
public class MainApp extends Application {
private static GsonBuilder gsonbuilder = new GsonBuilder();
但我得到编译错误:
Cannot resolve symbol 'GsonBuilder'
为什么在主应用中找不到gson lib?我通过 mytransport
模块使用它TRANSITIVE
Why it can't find gson lib in main app? I use it TRANSITIVE by mytransport
module
使用 api
而不是 implementation
.
在mytransport/build.gradle
:
dependencies {
//...
api 'com.google.code.gson:gson:2.8.5'
}
只是一个例子.
在library/build.gradle
:
dependencies {
api project(':libraryA')
}
在app/build.gradle
:
dependencies {
api project(':library')
}
在您的应用中,您将能够访问 both library
和 libraryA
.
In your app you will be able to access both library
and libraryA
.
使用实现
配置:
在library/build.gradle
:
dependencies {
implementation project(':libraryA')
}
在app/build.gradle
:
dependencies {
implementation project(':library')
}
在这种情况下,在您的应用中,您无法访问 libraryA 方法.
In this case in your app you can't access the libraryA methods.
这篇关于无法通过子模块的传递使用找到 lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!