簡體   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.

出於任何原因,我在同步 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM