Learning Android development, starting from the reference someone else's project
Almost three out of four days occurred during a variety of problems, now the recorded document is saved in blog park for later use.
Android studio run the whole process of external projects
Divided into seven steps
- Android studio pre-configured development environment
- Install android studio
- Import project gradle
- Modified version of build.gradle and gradle-wrapper.properties
- Sync project
- Choose to run the device select devices (Android third-party simulators, MUMU)
- Debug app or run
- Apk modify the name, the name of the application icon, rebuild apk
1. Configure android studio pre-development environment
First, go to the official website to download jdk oracle installer: https://www.oracle.com/technetwork/java/javase/downloads/index.html
Run the exe file, remember the installation directory, such as
The first case:
I installed the current directory to D: \ java1.8, jdk directory: D: \ java1.8 \ jdk, this installation is complete. Start configuration environment variable, right-click Computer Point Properties:
Open Environment Variables
In the System variables, click New to enter the establishment JAVA_HOME
Edit path (above) add the following two lines
In the system variables click New New CLASSPATH =;.% JAVA_HOME% \ lib;% JAVA_HOME% \ lib \ dt.jar;% JAVA_HOME% \ tools.jar (note that a small front point)
The second case:
Path:
CLASSPATH:
Command line respectively input java, javac, java -version, detects whether the installation is successful
2. Install android studio
Chinese community http://www.android-studio.org/ download the corresponding version (such as windows 64-bit)
All the way to run. If demand SDK can be downloaded after installing the SDK Manager.
Install type选择standard模式方便使用
3.导入工程gradle
打开android studio,file——new——import project
打开项目中的build.gradle文件(若提示项目已存在则打开整个文件夹即可)
导入之后会进行sync建立项目,如果一切顺利则可以在run——select devices中看到选项(即不是灰色的,如果不是灰色的就可以选择第三方安卓模拟器开始运行app了)
Sync的窗口会有错误提示
4.修改build.gradle和gradle-wrapper.properties的版本号
一般出现错误都是在这个环节,即版本号对应不上。重要的包括gradle版本等。
☆如果错误是“no value has been specificed”(kotlin),打开file——settings——plugins搜索kotlin是否已经下载(install),如果已下载则打开config.gradle文件查看kotlin版本号
这里是1.3.50,打开tools——kotlin——configure kotlin in project
选择all modules,版本号里选择1.3.50,ok,
成功之后build.gadle里会出现新的引用kotlin代码
重新sync文档,在file——sync project with gradle files中
☆如果错误是“ERROR: Cannot add task 'clean' as a task with that name already exists”,下图解决方案即可
☆如果是灰色的,在sync期间右下方屏幕窗口会出现错误提示。
当错误是Minimum supported Gradle version is 4.1. Current version is 2.14.1类似的情形时
将gradle-wrapper.properties这个文件打开,把圈出来的2.14.1改成4.1,然后点击gradle同步按钮就行了。(gradle同步在file——sync project with gradle)
如何查看当前项目的gradle版本?file——project structure打开,在project选项中可以看到gradle version和android plugin version。
☆当错误是 “使用了不支持的gradle版本,请使用gradle 1.10” 时,点击下方的蓝色连接“use default gradle wrapper”等待。
☆当错误是“defaultGroovMavenDeployer lose nexusUsername properties”和“需要更新新版本gradle插件时”时
打开build.gradle文件删除最后一行代码;将classpath那一行(ctrl+f搜索)的版本号改为当前gradle插件版本。
☆大部分错误都可以通过点击蓝色连接来修复,但是可能重新启动sync建立项目的时间会比较长。
☆sdk版本问题下载:在上述图中得知匹配sdk版本
可以考虑下载匹配版本。右上角的sdk manager中打开,勾选show package details(需要联网),可以下载指定sdk,如上述的28,类似的可以下载sdk tools。
☆“error: no value has been specified for this provider”问题(非kotlin)
5.Sync项目
Sync之后如果下方屏幕窗口全是绿色(没有红色error,黄色warning不用管)的,就可以开始进行下一步的第三方模拟器运行了。
6.选择运行设备select devices(第三方安卓模拟器,MUMU,需要在开启状态)
搜索网易mumu模拟器官网下载并安装
在mumu模拟器设置——属性设置中选择一个手机版本(例如huawei)
打开android studio,点击左下角的terminal
输入adb connect 127.0.0.1:7555
如果显示连接成功则在run——select devices中查看是否出现了手机huawei
如果出现则成功
7.Debug app或者run
运行成功,模拟器安装apk并运行app(可能运行时间较长,我是61s)
Run——Run app/Debug app
8.修改apk的名字、应用程序的名字图标、重新生成apk
Build.gradle中修改apk名字
修改应用程序图标
修改应用程序名字
App——manifest——androidmanifest
重新生成apk文件
生成apk之后会在右下方的命令窗口有提示,点击locate即可跳转到apk的文件地址。
其他错误:
INFO: API 'variant.getJavaCompiler()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()
2019年末过期?
今天是2019年12月24日平安夜···
结束
后记:博客园早点出图片粘贴功能啊,害的我还要把写在word里的图片一点点用截图工具截出来