簡體   English   中英

Android外部庫問題

[英]Android external library issue

我正在嘗試使用現有的Android項目作為我的應用程序的庫:

https://github.com/LarsWerkman/HoloColorPicker

Java代碼可以編譯,但是當我運行我的應用程序時,會發生以下錯誤:

java.lang.ClassNotFoundException: Didn't find class
"com.larswerkman.colorpicker.ColorPicker" on path: 
DexPathList[[zip file "data/app/myApp.apk"], nativeLibraryDirectories=
[/data/app-lib/myApp, /system/lib]]

我知道我不是第一個解決此異常的人,但是我確實沒有靈感。 我嘗試了以下方法:

  • 將項目包括在“屬性”->“ Android”->“添加...”中
  • 將項目包括在Java Build Path-> Projects-> Add ...
  • 在Java Build Path-> Order and Export中標記項目
  • 將.jar包含在Java構建路徑->庫->添加JAR中

這些都不能解決問題。 我想知道將項目包含為庫的正確方法是什么。

另外,ColorPicker項目的文檔說,我將此內容作為依賴項包括在內:

dependencies {
    compile 'com.larswerkman:HoloColorPicker:1.4'
}

我應該在哪個文件中包含它?

您應該將此包含在應用程序的build.gradle文件中。

這是build.gradle想要的:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.android.support:support-v4:+'
    compile 'com.larswerkman:HoloColorPicker:1.4'
}

剛剛看上面,我已經包含了HoloColorPicker庫。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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