Android HighCharts Library returns Error:Failed to resolve: com.highsoft.highcharts:6.0.2:

Android HighCharts Library returns Error:Failed to resolve: com.highsoft.highcharts:6.0.2:

几天前我看到 HighCharts Library 可用于 Android 图表。

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

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

Error:Failed to resolve: com.highsoft.highcharts:6.0.2:
Open File

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

A) You can download the aar from here: Highcharts and add it manually. Put the aar in the libs folder in your project structure.

B) You can add the library to the gradle dependecies from JCenter.

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

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

我的项目找不到 class HIGChartView。我无法确定这是我的附带问题还是 HighCharts 库问题。

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

我的build.gradle(模块:应用程序):

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'
}

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

他们的文档有问题 :

不正确 Class :

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

正确 Class :

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

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

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

另外,他们回复:

Unfortunatelly Highcharts Android is not avilable from jcenter yet so you need to add library manually. You can do that by following direct instructions from A) point from readme.

参考工作代码:

build.gradle(模块:应用程序):

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"/>