工作需要,尝试运行第三方SDK的demo,但是它是eclipse ADT,用Android Studio导入后,报以下错误:
1、Could not find com.android.tools.build:gradle:7.0.2.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'RegoDemo'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:7.0.2.
Searched in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
解决方法:在project
根目录的build.gradle
添加google()
:
buildscript {
repositories {
google()
...
}
}
allprojects {
repositories {
google()
...
}
}
如下:

2、Could not find method compile() for arguments [file collection]
A problem occurred evaluating project ':app'.
> Could not find method compile() for arguments [file collection]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
at build_9zrx3shc94jmbsa4m7q46jpc6$_run_closure2.doCall
(/Users/didi/AndroidStudioProjects/PrintDemo/RegoDemo/app/build.gradle:22)
app/build.gradle
报错代码如下:
dependencies {
compile files('libs/regoPrintLibV03.02.09.jar')
}
解决方法:将以上代码换成以下代码:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation files('libs/regoPrintLibV03.02.09.jar')
}
3、AAPT: error: '@+array/comName' is incompatible with attribute entries (attr) reference.
错误代码如下:
<Spinner
android:id="@+id/spinner_porttype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/Text_porttype"
android:entries="@+array/Interface" />
解决方法:去掉array前面的+号即可:
<Spinner
android:id="@+id/spinner_porttype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/Text_porttype"
android:entries="@array/Interface" />
网友评论