Android Studio 的一些 常用操作和 编译报错 整理(持续更新中...)
Android Studio 的一些 常用操作和 编译报错 整理(持续更新中...)
目录
Android Studio 的一些 常用操作和 编译报错 整理(持续更新中...)
一、Android studio 把一段代码快速提取,构建一个函数接口的方法
二、Android Studio 删除一个不要的 module 模块
三、Android Studio Debug调试一张图简单说明主要功能
四、Android Studio 3. 2 版本的多渠道打包的错误处理
五、Android Studio 杀死自己进程或者杀死指定进程
六、Android Studio 3.2 引入 aar 包进工程
七、@SuppressLint("NewApi") 和 @TargetApi() 的作用
八、解决"No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android"错误
九、Android Studio CPP/C 报错 calling convention '__stdcall' ignored for this target [-Wignored-attributes]
十、关于Android Studio3.2新建项目无法运行出现Failed to find Build Tools revision 28.0.2的解决方法
十一、Android设置自己的应用为launcher
十二、由于未及时更新Android 的一些库,可能会导致报错(可能也会导致Unity编包也会报错),这是可以使用国内的资源网址
十三、Android Studio 生成函数注释的实现方法
十四、Android Studio 快速把代码块定义为 region 块
一、Android studio 把一段代码快速提取,构建一个函数接口的方法
当我们在一个地方写了很多代码,想把它提取出来,放在自己定义的一个方法里面,只需要选中一些代码,然后操作快捷键 Cmd + Option + M(Mac) 就ok了,Windows是 Ctrl + Alt + M(如果你之前有把快捷键匹配成了eclipse的那么使用Alt+shift+M)。
二、Android Studio 删除一个不要的 module 模块
三、Android Studio Debug调试一张图简单说明主要功能
四、Android Studio 3. 2 版本的多渠道打包的错误处理
原编写:
productFlavors{wandoujia{//manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]}xiaomi{//manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]}}productFlavors.all { flavor ->flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]}applicationVariants.all { variant ->variant.outputs.each { output ->def outputFile = output.outputFileif (outputFile != null && outputFile.name.endsWith('.apk')) {def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")output.outputFile = new File(outputFile.parent, fileName)}}}
1)报错:
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=release, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
错误:Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=release, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
修改为:
productFlavors{wandoujia{//manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]}xiaomi{//manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]}}productFlavors.all { flavor ->flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]}applicationVariants.all { variant ->variant.outputs.all {def fileNamedef date = new Date()def formattedDate = date.format('yyyyMMdd')if (variant.buildType.name.equals('release')) {fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}-${formattedDate}.apk")}else if (variant.buildType.name.equals('debug')) {fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}-${formattedDate}.apk")}outputFileName = fileName;}}
2)报错:
提示:Error:All flavors must now belong to a named flavor dimension.Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
这个一个错误,意思是:所有的flavors都必须属于同一个风格。
提示:Error:All flavors must now belong to a named flavor dimension.Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
这个一个错误,意思是:所有的flavors都必须属于同一个风格。
添加代码:
在 defaultConfig 添加 flavorDimensions "versionCode",版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了
defaultConfig {applicationId "com.example.xan.testjsk"minSdkVersion 15targetSdkVersion 28versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"//版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了flavorDimensions "versionCode"
}
五、Android Studio 添加 aar 依赖的两种方式
1)方式一
android{repositories {flatDir {dirs 'libs'}}
}
dependencies {implementation fileTree(include: ['*.jar'], dir: 'libs')implementation (name: 'XX_library_vx.x.x', ext: 'aar')
}
2)方式二
android{//不用写/* repositories {flatDir {dirs 'libs'}}*/
}
dependencies {将implementation fileTree(dir: 'libs', include: ['*.jar'])改为implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
}
五、Android Studio 杀死自己进程或者杀死指定进程
1)杀死自己
android.os.Process.killProcess(android.os.Process.myPid());
2)杀死指定进程
a) activityManager.killBackgroundProcesses(不能杀死自己)
(注意:需要权限:<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>)
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses("com.android.mms");
b) activityManager.restartPackage("com.diandian")
(注意:需要权限: <uses-permission android:name="android.permission.RESTART_PACKAGES"/>)
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);activityManager.restartPackage("com.diandian");
六、Android Studio 3.2 引入 aar 包进工程
1)方法一:使用 implementation 添加 (最后记得 sync now)
2)添加 ‘*.aar’ (最后记得 sync now)
七、@SuppressLint("NewApi") 和 @TargetApi() 的作用
在我们日常开发Android当中,经常遇到写了一段正常的代码,但是系统报错,然后根据系统提示,会帮我们自动添加一个@SuppressLint(“NewApi”),
然后错误就撤销了原因是我们代码中使用了比我们所设置的
android:minSdkVersion= (即兼容最低版本)要高的方法
一般解决方法是在方法上加上@SuppressLint(“NewApi”)或者@TargetApi()或者设置更高的最低版本
1.@SuppressLint(“NewApi”)屏蔽一切因版本而导致新api中才能使用的方法报的android lint错误
2.@TargetApi() 屏蔽部分因版本而导致新api中才能使用的方法报的android lint错误
八、解决"No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android"错误
安装了Android Studio 3.2,打开一个旧工程,编译提示"No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android"
对新版NDK的研究,发现NDK的更新记录里有一段话
This version of the NDK is incompatible with the Android Gradle plugin
version 3.0 or older. If you see an error like
`No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android`,
update your project file to [use plugin version 3.1 or newer]. You will also
need to upgrade to Android Studio 3.1 or newer.
也就是说新版本的NDK与3.0及以前旧版的Android Gradle plugin插件不兼容
其实解决方法很简单,就是修改build.gradle中的红字部分,改为3.1以上版本即可
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
九、Android Studio CPP/C 报错 calling convention '__stdcall' ignored for this target [-Wignored-attributes]
解决方法:
Your best course of action is to use empty macros to make them go away.
#define __stdcall
十、关于Android Studio3.2新建项目无法运行出现Failed to find Build Tools revision 28.0.2的解决方法
解决: 去所创建项目下的app>build.gradle,打开build.gradle如下图 ,添加
buildToolsVersion "28.0.2"
十一、Android设置自己的应用为launcher
效果是让自己的应用在安卓设备启动后自动启动且显示为桌面(替换系统默认的launcher);
操作十分简单,在mainactivity的intent-fliter标签里添加下面的代码;
在AndroidManifest.xml 中添加,如下属性
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
这样重启以后系统会询问你是不是始终打开这个应用,或是仅此一次。
如果点了始终,就退不回以前的桌面了,想要修改的话,建议把上面四句话删除重新安装进安卓设备,以覆盖之前的应用。
十二、由于未及时更新Android 的一些库,可能会导致报错(可能也会导致Unity编包也会报错),这是可以使用国内的资源网址
buildscript {repositories {/*jcenter()maven {url 'https://maven.google.com/'name 'Google'}google()*/maven {url 'https://maven.aliyun.com/repository/google'}maven {url 'https://maven.aliyun.com/repository/jcenter'}maven {url 'https://maven.aliyun.com/nexus/content/groups/public'}}dependencies {classpath 'com.android.tools.build:gradle:3.2.1'// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}
}allprojects {repositories {/*jcenter()maven {url 'https://maven.google.com/'name 'Google'}*/maven {url 'https://maven.aliyun.com/repository/google'}maven {url 'https://maven.aliyun.com/repository/jcenter'}maven {url 'https://maven.aliyun.com/nexus/content/groups/public'}}
}task clean(type: Delete) {delete rootProject.buildDir
}
十三、Android Studio 生成函数注释的实现方法
1、函数名上输入
---> /**,然后回车,即自动生成基本注释(参数,返回等)
2、使用快捷键生成
---> 鼠标停留在函数体内,按下设置的快捷键即可生成基本注释
快捷键设置方法:在"Fix doc comment"上右键进行快捷键设置。
十四、Android Studio 快速把代码块定义为 region 块
1、window 上的快捷方式
先选择要折叠的一组代码
按下快捷键Ctrl+Alt+T
在弹出的菜单中选择region...endregion Comments
2、Mac 上的操作
将某一功能的多个方法或变量放在一起
选中该区域的代码,按快捷键
cmd +option + z
( surround with... )选择
region...endregion Comments
这样就会自动在选中的代码最开始会最后生成region和endregion注释,自己再添加下分组的注释说明就ok了。
Android Studio 的一些 常用操作和 编译报错 整理(持续更新中...)相关推荐
- Android Studio 第一次安装启动Failed to resolve报错解决方案
笔者近期准备着手做一个有关安卓的项目,兴冲冲地找来Android学习书籍,并下载安装了Android Studio.可是在Android Studio的第一次运行就遇到了很大的问题,各种莫名其妙的报错 ...
- Android Studio Day03-2(常用操作)
(1)选择文本 1.Ctrl+A 选中全文 2.在将光标置于任意的单词中时按住Ctrl+W,选中整个词 继续按Ctrl+W 选中的区域将扩大,扩大至包含任意数量的相邻的单词 按Ctrl+w+Shif ...
- 【Android】多模块工程移动目录编译报错:Could not determine the dependencies of task ‘:app:compileDebugJavaWithJavac‘
1 背景 事情是这样的,最近在利用组件化的方式开发一个多模块工程,看着模块越来越多,于是想把某些同一层级的模块放到同一个目录下,如下: 可以直接将相应模块拖动到目标目录下,也可以如下所示,在模块上右键 ...
- Android Studio升级后,新建Activity始终报错,创建不了
今天升级Android Studio到3.0后,3.0的新特性还是让人挺喜欢的,但是当我新建一个Activity发现始终报错 Error executing FreeMarker template: ...
- Android Studio第一次下载安装SDK更改目录报错的
第一次安装Android Studio需要下载Android SDK默认是下载到C:\windows\user\username\appDate\local\Android\Sdk里的. 因为SDK体 ...
- 2022年最新版Android安卓面试题+答案精选(每日20题,持续更新中)【十】
前言 好久不见,甚是想念.各位朋友们,我又携带着最受大家欢迎的面试题回来了,可能会有朋友要问了:哎呀,你咋不更了,这不是上次那一份资料用完了嘛,这不,我又厚着脸皮去问我们公司的主管:Boss,给我份面 ...
- android环境搭建出错,androidstudio配置环境遇到的各种错误(持续更新中)
AndroidStudio3.0,gradle4.1,新建工程,遇到如下错误: Error:Unable to resolve dependency for ':app@debugAndroidTes ...
- 【presto】presto编译报错整理(大全)
问题一: 报错信息: 1) Explicit bindings are required and com.facebook.presto.execution.TaskManager is not ex ...
- 【atlas】atlas 编译报错整理(全)
前言 最近在编译 apache altas 1.1版本.在编译过程中遇到很多报错,这里整理并记录一下. 问题一: org.restlet.jee 包找不到 问题原因 Maven主仓库中找不到包的解决办 ...
最新文章
- 织梦首页常用调用标签
- Python 变量类型
- [云炬创业学笔记]第一章创业是什么测试16
- JeecgUniapp移动框架 2.0版本发布,一份代码多终端适配
- linux下执行java_Linux下运行java项目
- iOS 2x 3x
- python-json下载以及分析-案例
- 计算机网络技术教研活动,(2012.09.27)计算机网络技术专业教研活动(文本).doc...
- 板内板间通信协议及接口(七)现场总线及modbus协议
- 支持中文!秒建 wiki 知识库的开源项目,构建私人知识网络
- CSAPP第四章家庭作业参考答案
- 正则表达式之前瞻后顾
- PHP 使用 file_get_contents 接收 POST 的資料
- 网易16年研发实习生笔试题 - 寻找第K大
- 图片内容巴特勒 (隐藏文字到图片)
- 学生用计算机app,学生方程计算器
- 千山独行-一个人的创业路(连载一)
- Android.mk编译java动态库
- ubuntu WPS 报错系统缺失字体symbol、wingdings、wingdings 2、wingdings 3
- 【驱动代码移植高通平台之二十三】高通平台i2c设备驱动