简体   繁体   中英

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.

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:

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

I have checked that the class exists inside the.jar file.

This is how I implemented the library project in my app build.gradle:

implementation project(":library_project_name")

settings.properties:

include ':app', ':library_project_name'

This is the library project's 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:

import com.dspread.xpos.QPOSService;

Any ideas of why might this be happening??

Option 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:

but it only works when I change

compileSdkVersion 
minSdkVersion 
targetSdkVersion 

in app and the other modules are the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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