0

我正在开发一个 Android 应用程序项目。它基于 Web 服务和 SOAP 协议。我有 ksoap2-android-assembly-2.4-jar-with-dependencies.JAR 库,以便使用 SoapObject 等类。我将它放在 libs 目录下并将其设置为库。

错误是

org.gradle.internal.exceptions.LocationAwareException:任务':app:javaPreCompileDebug'的执行失败。org.gradle.api.internal.artifacts.transform.TransformException:IdentityTransform 执行失败:D:\Android\All Crops 03-May-19\xxxxxxx\app\libs\ksoap2-android-assembly-2.4-jar-with-依赖项.jar。

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 fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation files('libs/ksoap2-android-assembly-2.4-jar-with-dependencies.jar')
    //implementation files('libs/ksoap2-android-assembly-3.5.0.jar')
    implementation 'com.android.support:cardview-v7:28.0.0'


}
4

1 回答 1

0

如果您使用不同的方法来引入 jar 依赖项,这些是我为使其工作而采取的步骤:

  • 我从这里下载了...2.4-jar-with-dependencies.jar文件
  • 我验证了我的应用程序模块中存在 libs 文件夹,如下所示(如果不存在,请创建它):

应用程序/库

  • 然后我将下载的文件粘贴到我的app/libs文件夹中,右键单击 jar 库,然后在列表底部单击Add as Library

添加为库

在它自动生成 gradle 依赖项后,我可以SoapObject在我的 Activity 中访问和使用。


我在运行 Android Studio 3.5 的 MacO 上,使用 androidx 而不是支持库:我正在使用androidx.constraintlayout:constraintlayout:1.1.3而不是com.android.support.constraint:constraint-layout:1.1.3

我的 gradle 发行版...gradle-5.4.1-all.zip在 build.gradle (Project) 中,我使用的是 3.5.0:

dependencies { classpath 'com.android.tools.build:gradle:3.5.0' }

在 gradle.properties 中,我设置了android.useAndroidX=trueandroid.enableJetifier=true

如果按照上述步骤操作(或者如果您已经这样做了)并且它仍然无法正常工作,您可能必须删除您的.gradle文件夹并重新构建。这可能是因为您将 Android Studio 更新到 3.5,但项目的 gradle 也没有更新。

于 2019-09-19T07:30:28.920 回答