【问题标题】:How to import .jar file in module and also in application?如何在模块和应用程序中导入 .jar 文件?
【发布时间】:2019-04-09 13:38:48
【问题描述】:

我有一个项目(MyProject),其中有一个库(customlib)模块,该库模块正在使用我导入的 int 模块的一个 jar 文件 commontask.jar。我也想在 android 项目中使用相同的 jar 文件。我在 MyProject 中导入了该模块(customlib),但是如果我尝试访问自定义库的类(CustomActivity.java),那么它给出的错误是无法访问 CustomActivity.java。

customlib gradle 文件

apply plugin: 'com.android.library'

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation files('libs/customtask.jar')
}

我的项目 gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    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 project(':customlib')
}

如果我在该项目中导入该 customtask.jar,并且当我生成 apk 时出现错误

Program type already present: com.task.common.Helper

【问题讨论】:

  • 你检查过这个 StackOverflow question吗?

标签: android android-gradle-plugin


【解决方案1】:

原始问题(更新前)

如何在模块和android应用程序中导入.jar文件?

答案:

  • 对于 .jar 文件,您可以将它们添加到 Android Studio 项目的 app 文件夹中

  • 然后以 Project View 和 app 文件夹的形式打开 Android Studio 项目,右键单击 jar 文件并选择添加为库。


1.在项目视图中打开 Android Studio

2。打开应用>>通过右键单击应用创建库包。在库中添加你的 .jar 文件。

3.然后右键单击您的 .jar 文件并将其添加为库

【讨论】:

  • 我把它放在那里然后它在构建 apk 程序类型已经存在时给出了这个错误:com.task.common.Helper
  • 你按照上面的方法操作了吗?
  • 是,但无法将 .jar 文件类访问到我的应用程序中
  • 访问它有什么问题?如果是作为 Library 导入的,可以使用
  • @AliAhmed 我按照这些步骤操作,但仍然无法访问所有文件。错误是“无法解析符号”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-02
  • 1970-01-01
  • 2021-02-04
相关资源
最近更新 更多