AndroidStuio打开一个已存在的项目

开源项目:扫一扫

下载zxing-master通过AndroidStudio直接打开构建时提示Gradle问题,不了解Gradle怎么回事,更具提示dowload失败了。

于是百度尝试第二种方式,如下:

1.AndroidStudio本地先创建一个空项目OpenSource-scaner

2.根据OpenSource-scaner创建自动生成的Gradle配置文件修改zxing-master中对应的文件。

- app/build.gradle

compileSdkVersion、buildToolsVersion、minSdkVersion、targetSdkVersion

-gradle/wrapper/gradle-wrapper.properties

distributionUrl

-build.gradle

classpath

3.AndroidStudio->file->open打开zxing

4.等待Gradle同步

Gradle sync这时成功了。

5.(工具栏中的锤子)ctrl+F9构建一下

6.这时app/release路径下有zxing.apk生成

安装生成的apk到手机中,试了下识别出二维码内容。

问题

1.安装apk提示

Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Package /data/app/vmdl924957567.tmp/base.apk has no certificates at entry AndroidManifest.xml]
原因:打包的apk没签名,app-release-unsigned.apk。

解决:根据zxing-master build.gradle添加签名,然后构建apk。

具体操作如下:

step1:AndroidStudio Build -> Generate Signed Bundle or APK -> APK,然后next。

step2:根据项目build.gradle添加签名信息

  Key store path选择项目自带的zxing.jks。

  Key store password:123456

  Key alias:zxingyzq

  Key password:123456

step3:Build -> Make Project构建apk

这时在zxing-masterappuildoutputsapkdebug会生成签名apk:app-debug.apk

step4:adb install app-debug.apk安装apk

 2.打开开源Gradle Sync时提示:NDK not configured

原因:这次是因为NDK版本不一致找不到NDK导致的。

解决:指定NDK路径

step1:右上角,打开搜索窗口,输入Project Structure ...

step2:选Project Structure窗口download Android NDK,选择NDK的路径,然后apply

step3:重新同步加载

3.导入提示:Your project path contains non-ASCII characters

原因:

解决:添加android.overridePathCheck=true到gradle.properties

 4.sync时

Cause: com.android.builder.sdk.LicenceNotAcceptedException: Failed to install the following Android SDK packages as some licences have not been accepted.
ndk;21.3.6528147 NDK (Side by side) 21.3.6528147
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

Using Android SDK: D:Program FilesAndroidSDK
Failed to install the following Android SDK packages as some licences have not been accepted.
ndk;21.3.6528147 NDK (Side by side) 21.3.6528147
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

Using Android SDK: D:Program FilesAndroidSDK

 解决:进入AndroidSDK oolsin,cmd执行:sdkmanager.bat --licenses ,一路y

5.

Location specified by ndk.dir (/Users/dp/Library/Android/sdk/ndk-bundle) did not contain a valid NDK and and couldn't be used

解决:注掉local.properties中n

dk.dir=/Users/dp/Library/Android/sdk/ndk-bundle

7.

Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve project :openCVLibrary401.
Required by:
project :app
Caused by: org.gradle.internal.component.NoMatchingConfigurationSelectionException: Unable to find a matching configuration of project :openCVLibrary401:
- None of the consumable configurations have attributes.

 8.

ERROR: Library projects cannot set applicationId. applicationId is set to 'org.opencv' in default config.
Affected Modules: openCVLibrary401

原因:OpenCV-sdk导入时build.gradle配置中参数不正确

修改前:

defaultConfig {
applicationId "org.openCV"
}
应修改:
defaultConfig {
applicationId "org.openCVLibrary401"
}
这个和工程中导入依赖对应,

参考链接:

https://docs.gradle.org/current/userguide/compatibility.html#compatibility

https://docs.gradle.org/current/userguide/installation.html

原文地址:https://www.cnblogs.com/yemaomao/p/12957803.html