首页 > 解决方案 > 我在安装库时遇到问题

问题描述

我正在尝试使用jlatemath库。
我已将 .jar 文件放在 libs 文件夹下,这是我的 gradle。

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation files('libs/jlatexmath-android-0.1.0-sources.jar')
    implementation files('libs/jlatexmath-android-font-cyrillic-0.1.0-sources.jar')
    implementation files('libs/jlatexmath-android-font-greek-0.1.0-sources.jar')
}

我不认为我需要两者,但我只是为了确定。

我尝试清理并重建项目。

没有runtask,构建没有问题,
但我的代码仍然没有从库中找到类,这意味着没有找到类的自动导入。

这是我第一次使用图书馆,所以我可能错过了一些愚蠢的东西,但如果有人能告诉我它是什么,我将不胜感激。

标签: javaandroidandroid-gradle-pluginshared-libraries

解决方案


按着这些次序 我刚刚注意到的是您正在尝试手动下载和添加依赖项。这是一个非常漫长而令人厌烦的过程!您可以粘贴并让 android studio 为您完成。

对于您的情况,您需要在 build.gradle 添加这些行

    implementation 'ru.noties:jlatexmath-android:0.1.0'

    // for Cyrillic symbols
    implementation 'ru.noties:jlatexmath-android-font-cyrillic:0.1.0'

并同步项目。不要忘记删除之前手动添加依赖项的所有行。

所以你在问题中的代码应该如下所示

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


    //PASTE HERE DEPENDENCIES

    implementation 'ru.noties:jlatexmath-android:0.1.0'

    // for Cyrillic symbols
    implementation 'ru.noties:jlatexmath-android-font-cyrillic:0.1.0'
}

如果它没有解决您的问题,请告诉我。

如果您更喜欢视频教程,您可以按照本教程了解如何在 android studio 中添加依赖项。


推荐阅读