简体   繁体   English

无法在我的库实现中访问 class

[英]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. 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.

For any reason I when I sync Gradle everything is ok, but when I click on Run app to test my app the next error is showen in build:出于任何原因,我在同步 Gradle 时一切正常,但是当我单击运行应用程序以测试我的应用程序时,构建中显示了下一个错误:

error: cannot access QPOSService
class file for com.dspread.xpos.QPOSService not found

I have checked that the class exists inside the.jar file.我检查了 class 存在于 .jar 文件中。

This is how I implemented the library project in my app build.gradle:这就是我在我的应用程序 build.gradle 中实现库项目的方式:

implementation project(":library_project_name")

settings.properties:设置.属性:

include ':app', ':library_project_name'

This is the library project's Gradle:这是库项目的 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'
}

This is how I import the class inside my Activity:这就是我在我的活动中导入 class 的方式:

import com.dspread.xpos.QPOSService;

Any ideas of why might this be happening??关于为什么会发生这种情况的任何想法?

Option 1:选项1:

Using the command line, in the root of your project, run:使用命令行,在项目的根目录中运行:

./gradlew clean && ./gradlew build

Then recompile your project in studio and you should see your new lib.然后在工作室中重新编译你的项目,你应该会看到你的新库。

Option 2:选项 2:

but it only works when I change但它只在我改变时才有效

compileSdkVersion 
minSdkVersion 
targetSdkVersion 

in app and the other modules are the same.app和其他模块是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM