[英]Cannot access class inside my library implementation
I am trying to access a class that is inside a.jar file ( dspread-android_sdk_2.6.3.jar
), this.jar file has been implemented by a library project and the library project is being implemented by my main app project.
出于任何原因,我在同步 Gradle 时一切正常,但是当我单击运行应用程序以测试我的应用程序时,构建中显示了下一个错误:
error: cannot access QPOSService
class file for com.dspread.xpos.QPOSService not found
我检查了 class 存在于 .jar 文件中。
这就是我在我的应用程序 build.gradle 中实现库项目的方式:
implementation project(":library_project_name")
设置.属性:
include ':app', ':library_project_name'
这是库项目的 Gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
//sourceCompatibility = '1.8'
//targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.android.volley:volley:1.1.1'
}
task copyLibs(type: Copy) {
from configurations.compile
into 'libs'
}
task exportJar(type: Copy) {
from('build/intermediates/bundles/release/')
into 'libs'
include 'dspread-android_sdk_2.6.3.jar'
}
这就是我在我的活动中导入 class 的方式:
import com.dspread.xpos.QPOSService;
关于为什么会发生这种情况的任何想法?
选项1:
使用命令行,在项目的根目录中运行:
./gradlew clean && ./gradlew build
然后在工作室中重新编译你的项目,你应该会看到你的新库。
选项 2:
但它只在我改变时才有效
compileSdkVersion
minSdkVersion
targetSdkVersion
在app
和其他模块是相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.