Android编译库错误

时间:2015-01-15 18:36:05

标签: android android-studio build.gradle

我正在尝试使用库NCHART3D

我的build.gradle

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.android.test3dchart"
        minSdkVersion 16
        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 files('libs/NChart3D.jar')
}

和logcat打印:

Couldn't load nchart3d from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.android.test3dchart-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.test3dchart-2, /vendor/lib, /system/lib]]]: findLibrary returned null

01-15 13:29:50.177    2793-2793/com.example.android.chart D/dalvikvm﹕ Late-enabling CheckJNI
01-15 13:29:50.267    2793-2793/com.example.android.chart W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/nulana/NChart/NChartView;
01-15 13:29:50.267    2793-2793/com.example.android.chart W/dalvikvm﹕ Class init failed in Constructor.constructNative (Lcom/nulana/NChart/NChartView;)
01-15 13:29:50.267    2793-2793/com.example.android.chart D/AndroidRuntime﹕ Shutting down VM
01-15 13:29:50.267    2793-2793/com.example.android.chart W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415778b0)
01-15 13:29:50.277    2793-2793/com.example.android.chart E/AndroidRuntime﹕ FATAL EXCEPTION: main

更新 在xml预览中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.nulana.NChart.NChartView
        android:id="@+id/surface"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"/>
</LinearLayout>

渲染问题找不到以下类: - com.nulana.NChart.NChartView(修复构建路径,创建类)  提示:尝试构建项目。

1 个答案:

答案 0 :(得分:1)

我想这是因为冗余,在下面的代码第一行已经包括你的jar了。

compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/NChart3D.jar')

尝试删除编译文件(&#39; libs / NChart3D.jar&#39;),然后清理项目并重建

确保您有以下项目结构,并注意您的jar应该进入libs文件夹和jniLibs中的其他lib组件。这是为android studio 1.0

project tree