android开发笔记,杂
Mapping文件地址:
mapping文件用于在代码被混淆后,还原BUG信息。
release模式编译项目即可产生,相对位置:工程\build\outputs\mapping\release
需要clean project能解决的:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDevDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/ultrapower/mcs/engine/AudioCodecInfo.class
debug卡在waiting for debugger
解决方法:重启adb。
步骤:cmd进入命令行,进入adb所在目录先后执行adb kill-server,adb start-server。
获取APP版本号
/** * 获取程序版本,参考build.gradle里面的versionName * * @param context * @return */ public static String getVersionName(Context context) { PackageManager packageManager = context.getPackageManager(); try { PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0); return packInfo.versionName; } catch (PackageManager.NameNotFoundException e) { return ""; } }
在桌面创建多个快捷方式
在指定的Activity的androidmanifest.xml加入LAUNCHER的category
<intent-filter> <!--加入Launcher就可以了--> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter>
No Application Debuggable
断点进不去,解决办法:
在gradle文件的debug和release属性下,加入
debuggable true
举例
去应用市场给apk打分
Uri uri = Uri.parse("market://details?id="+getPackageName()); Intent intent = new Intent(Intent.ACTION_VIEW,uri); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
自动在release模式下,混淆、压缩
打开app的build.gradle,参考下面代码进行修改
apply plugin: 'com.android.application' //创建当前时间字符串 比如 0411_1213 表示 4月11号,12点13分 def buildTime() { def date = new Date() def formattedDate = date.format('MMdd_HHmm') return formattedDate } android { compileSdkVersion 23 buildToolsVersion "23.0.2" signingConfigs { release { keyAlias 'kimmy' keyPassword '123456' storeFile file('../test.jks') storePassword 'xl123456' } } defaultConfig { applicationId "com.zhexian.learn.myapplication" minSdkVersion 14 targetSdkVersion 23 versionCode 77 versionName "1.0" } buildTypes { release { debuggable true shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release applicationVariants.all { variant -> variant.outputs.each { output -> if (output.outputFile != null && output.outputFile.name.endsWith('.apk') && 'release'.equals(variant.buildType.name)) { String flavorName = variant.flavorName; String versionName = variant.versionName; String parentFile = output.outputFile.getParent(); if (flavorName != null && !flavorName.equals("")) { output.outputFile = new File(parentFile, "${variant.buildType.name}_${flavorName}_v${versionName}_${buildTime()}.apk") } else { output.outputFile = new File(parentFile, "release_v${versionName}_${buildTime()}.apk") } } } } } debug { debuggable true jniDebuggable true minifyEnabled false shrinkResources false pseudoLocalesEnabled false signingConfig signingConfigs.release } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端