简体   繁体   English

Android外部库问题

[英]Android external library issue

I am trying to use an existing Android project as a library for my app: 我正在尝试使用现有的Android项目作为我的应用程序的库:

https://github.com/LarsWerkman/HoloColorPicker https://github.com/LarsWerkman/HoloColorPicker

The java code compiles, but when I run my app the following error occurs: 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]]

I know that I am not the first to address this exception, but I am really out of inspiration. 我知道我不是第一个解决此异常的人,但是我确实没有灵感。 I tried the following: 我尝试了以下方法:

  • Include the project in Properties -> Android -> Add... 将项目包括在“属性”->“ Android”->“添加...”中
  • Include the project in Java Build Path -> Projects -> Add... 将项目包括在Java Build Path-> Projects-> Add ...
  • Mark the project in Java Build Path -> Order and Export 在Java Build Path-> Order and Export中标记项目
  • Include the .jar in Java Build Path -> libraries -> Add JARs 将.jar包含在Java构建路径->库->添加JAR中

NONE of these fixes the problem. 这些都不能解决问题。 I want to know what the propper way is to include a project as a library. 我想知道将项目包含为库的正确方法是什么。

Also, the documentation of the ColorPicker project, says that I include this somewhere as a dependency: 另外,ColorPicker项目的文档说,我将此内容作为依赖项包括在内:

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

In what file should I include this? 我应该在哪个文件中包含它?

You should include this in build.gradle file of your application. 您应该将此包含在应用程序的build.gradle文件中。

This is how build.gradle would like: 这是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'
}

Just see above I have included HoloColorPicker library. 刚刚看上面,我已经包含了HoloColorPicker库。

在此处输入图片说明

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

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