【问题标题】:Android Development: Unresolved reference using Java library in Kotlin appAndroid 开发:在 Kotlin 应用程序中使用 Java 库的未解决参考
【发布时间】:2020-03-01 05:52:51
【问题描述】:

我正在尝试在我的 Android 应用程序中使用 Java AnyChart 数据可视化库 (https://github.com/AnyChart/AnyChart-Android)。但是,当我尝试为应用添加所需的导入时:

import com.anychart.AnyChart;
import com.anychart.AnyChartView;
import com.anychart.DataEntry;
import com.anychart.Pie;
import com.anychart.ValueDataEntry;

我收到以下错误:

Unresolved reference: DataEntry
Unresolved reference: Pie
Unresolved reference: ValueDataEntry

这似乎很奇怪,因为我的 gradle 编译没有错误,并且前两个语句没有显示“未解析的引用”错误。我试过使缓存失效并重新启动,但没有奏效。我曾尝试用com.anychart.anychart 替换com.anychart,但这也没有用。

【问题讨论】:

    标签: java android kotlin dependencies


    【解决方案1】:

    错别字:

    import com.anychart.AnyChart;
    import com.anychart.AnyChartView;
    import com.anychart.DataEntry;
    import com.anychart.Pie;
    import com.anychart.ValueDataEntry;
    

    解决方案:

    import com.anychart.anychart.AnyChart;     // Based off of the link
    import com.anychart.anychart.AnyChartView; // Based off of the link
    import com.anychart.anychart.DataEntry;
    import com.anychart.anychart.Pie;
    import com.anychart.anychart.ValueDataEntry;
    

    另外,我通过查看here 找到了这个。

    【讨论】:

    • 好的,然后尝试只更改最后 3 个导入。
    【解决方案2】:

    你可能错过了这部分:

    a) 将此添加到存储库末尾的根 build.gradle

    allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }
    

    b) 将依赖添加到项目build.gradle:

    dependencies {
        implementation "com.github.AnyChart:AnyChart-Android:1.1.2"
    }
    

    就是com.anychart.AnyChart

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-11
      • 1970-01-01
      相关资源
      最近更新 更多