【问题标题】:Android HighCharts Library returns Error:Failed to resolve: com.highsoft.highcharts:6.0.2:Android HighCharts 库返回错误:无法解析:com.highsoft.highcharts:6.0.2:
【发布时间】:2018-03-12 10:31:43
【问题描述】:

几天前我看到 HighCharts Library 可用于 Android for graph。

https://github.com/highcharts/highcharts-android

我阅读了文档并启动它以添加到我的项目中,但是当我尝试将 gradle 添加到我的项目时出现错误:

错误:无法解决:com.highsoft.highcharts:6.0.2:
打开文件

他们在文档中提到了两种方法:

A) 您可以从此处下载 aar:Highcharts 并手动添加。将 aar 放在项目结构的 libs 文件夹中。

B) 您可以将库添加到 JCenter 的 gradle 依赖项中。

当我将 .aar 文件添加到 libs 文件夹时没有问题,但是当我添加以下代码时:

HIGChartView chartView = (HIGChartView) findViewById(R.id.hc);

我的项目无法找到课程HIGChartView。我无法确定这是我的次要问题还是 HighCharts 库问题。

我还下载了 Github 的项目,在他们的项目上没有问题,也将 Gradle 与他们的项目进行比较,但我无法找出问题。

我的build.gradle(Module:App):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.kabloom.highcharts2"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'

    implementation 'com.highsoft.highcharts:6.0.2' // HighCharts here added

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

【问题讨论】:

    标签: android highcharts android-highcharts


    【解决方案1】:

    在 github 上创建问题后,他们回复并解决了我的问题...

    他们的文档有问题

    类不正确:

    HIGChartView chartView = (HIGChartView) findViewById(R.id.hc);
    

    正确分类:

    HIChartView chartView = (HIChartView) findViewById(R.id.hc);
    

    请注意,该库需要 Gson 才能工作,因此请将其添加到您的依赖项中,如下所示:

    compile 'com.google.code.gson:gson:2.8.0'
    

    另外,他们回答:

    不幸的是,jcenter 还没有提供 Highcharts Android 您需要手动添加库。您可以直接按照以下方式进行操作 A) 中的说明来自自述文件。

    参考工作代码:

    build.gradle(Module:App):

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "com.package_name.highchartdemo"
            minSdkVersion 21
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
    }
    
    repositories{
        flatDir{
            dirs 'libs'
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        compile (name: 'highcharts-release', ext:'aar')
        compile 'com.google.code.gson:gson:2.8.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }
    

    主活动:

       package com.package_name.highchartdemo;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    import com.highsoft.highcharts.Core.*;
    import com.highsoft.highcharts.Common.HIChartsClasses.*;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            HIChartView chartView = (HIChartView) findViewById(R.id.hc);
    
            HIOptions options = new HIOptions();
    
            HIChart chart = new HIChart();
            chart.type = "column";
            options.chart = chart;
    
            HITitle title = new HITitle();
            title.text = "Demo chart";
    
            options.title = title;
    
            HIColumn series = new HIColumn();
            series.data = new ArrayList<>(Arrays.asList(49.9, 71.5, 106.4, 129.2, 144, 176, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4));
            options.series = new ArrayList<HISeries>(Collections.singletonList(series));
    
            chartView.options = options;
        }
    }
    

    activity_main:

        <?xml version="1.0" encoding="utf-8"?>
    <com.highsoft.highcharts.Core.HIChartView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:id="@+id/hc"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.package_name.highchartdemo.MainActivity"/>
    

    【讨论】:

    • 我在&lt;com.highsoft.highcharts.core.HIChartView 遇到问题,请查看我的question
    猜你喜欢
    • 1970-01-01
    • 2021-02-28
    • 2012-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    • 2017-07-08
    • 2023-04-02
    相关资源
    最近更新 更多