【问题标题】:android studio, which import statement to use external libs?android studio,使用外部库的导入语句?
【发布时间】:2017-05-08 08:32:31
【问题描述】:

我将 EJML 库添加到我的 android studio 项目中,但我不知道导入语句的样子。

我的意思是,我必须写什么才能使用这些库?

我的依赖:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile files('libs/EJML-core-0.30.jar')
compile files('libs/EJML-core-0.30-sources.jar')
compile files('libs/EJML-dense64-0.30.jar')
compile files('libs/EJML-dense64-0.30-sources.jar')
compile files('libs/EJML-denseC64-0.30.jar')
compile files('libs/EJML-denseC64-0.30-sources.jar')
compile files('libs/EJML-equation-0.30.jar')
compile files('libs/EJML-equation-0.30-sources.jar')
compile files('libs/EJML-simple-0.30.jar')
compile files('libs/EJML-simple-0.30-sources.jar')
compile files('libs/EJML-core-0.30-sources.jar')

}

【问题讨论】:

  • 如果你给我一个-1,请告诉我原因。

标签: java android android-studio import


【解决方案1】:

在您的应用级别 build.gradle 文件中,您将有一个 dependencies 部分。

请参阅How to add local .jar file dependency to build.gradle file? 了解更多信息。

所以你的情况是:

dependencies {
    ... library files that are already there
    compile files('libs/EJML-core-0.30.jar')
    compile files('libs/EJML-core-0.30-sources.jar')
    ... the libraries in your libs folder will follow the same pattern
}

编辑:从 cmets 添加。

但我不知道导入语句的样子:import ....

如果您只使用 JAR 文件中的一个类,例如,如果我为 RecyclerView 添加一个依赖项(例如:compile 'com.android.support:recyclerview-v7:25.0.1'),我会调用 RecyclerView recyclerView = new RecyclerView() 等等会要求你在那里导入它。我不知道你编译的JARs需要什么类。

【讨论】:

  • 谢谢,但我不知道导入语句的样子:import ....
  • 如果您只使用 JAR 文件中的一个类,例如,如果我为 RecyclerView 添加依赖项(例如:compile 'com.android.support:recyclerview-v7:25.0.1')然后我会调用 RecyclerView recyclerView = new RecyclerView() 等,它会要求您将其导入那里。我不知道你编译的 JAR 需要哪些类。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-22
  • 1970-01-01
  • 2013-07-12
  • 2013-12-18
  • 2020-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多