android studio 导入jar无效,Android Studio导入jar时遇到的问题

在Android Studio中遇到导入jar包无效的问题,错误提示表明不能将提供的表示转换为Dependency类型。解决方案是修改Module的build.gradle文件,将dependencies节点下关于jar的编译语句改为'compile files('...')'格式,例如:compile files('libs/ksoap2-android-assembly-3.4.0.jar')。参考StackOverflow上的解答可以解决此类问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先贴上Log:

Error:(25, 0) Cannot convert the provided notation to an object of type Dependency: /HomePath/workspaceAppProject/WeatherWebService/app/libs/ksoap2-android-assembly-3.4.0-jar-with-dependencies.jar.

The following types/formats are supported:

- Instances of Dependency.

- String or CharSequence values, e.g. 'org.gradle:gradle-core:1.0'.

- Maps, e.g. [group: 'org.gradle', name: 'gradle-core', version: '1.0'].

- FileCollections, e.g. files('some.jar', 'someOther.jar').

- Projects, e.g. project(':some:project:path').

- ClassPathNotation, e.g. gradleApi().

Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type.

出现了这个错误难免,我们看看Module的build.gradle文件下dependencies这个节点是如何写的:

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:appcompat-v7:22.0.0'

compile file('libs.ksoap2-android-assembly-3.4.0.jar')

}

在google了一通之后,找到了如下答案:

The dependency should read "compile files(...)", not "compile file(...)".

Also in the above you write the path as 'libs.achartengine-1.1.0.jar', this should be 'libs/achartengine-1.1.0.jar'

所以正确的写法应该是:

compile files('libs/ksoap2-android-assembly-3.4.0.jar')

参考链接:http://stackoverflow.com/questions/19176721/adding-a-library-android-studio

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值