Android开发问题记录

0.开发环境:

  • Android Studio 3.2
  • Build #AI-181.5540.7.32.5014246, built on September 18, 2018
  • JRE: 1.8.0_152-release-1136-b06 amd64
  • JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  • Windows 10 10.0

1.Android Studio导入新项目,gradle报 read timed out的情景之一

  • 由于项目的sdk没有使用自己下载的jdk,而是使用AndroidStudio默认的jre目录,所以导致这个问题。勾去掉即可:

Android开发问题记录_第1张图片

2.找不到R文件

  • 原因之一:资源文件导入不正确
  • 解决方法:Build一下Project,查看编译器的提示,修改资源文件配置

3.删除project下的module

  • File->Project Structure,选中要删除的module,点击红色减号按钮
  • 在Project视图下,选中要删除的module,右键,点击delete(注意,删除之后不可撤销,回收站也找不回来)

4.gradle sync太慢

  • 原因之一:被墙了
  • 解决方法:使用镜像,在Project下的build.gradle中添加以下代码
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public'}
        //jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public'}
        //jcenter()
    }
}

4.AndroidManifest.xml文件中,Application提示警告:App is not indexable by Google Search; consider adding at least one Activity with an ACTION-VIEW intent-filler

原因:

To enable Google to crawl your app content and allow users to enter your app from search results, you must add intent filters for the relevant activities in your app manifest. These intent filters allow deep linking to the content in any of your activities. For example, the user might click on a deep link to view a page within a shopping app that describes a product offering that the user is searching for.
要使Google能够抓取您的应用内容并允许用户从搜索结果中进入您的应用,您必须为manifest中的相关活动添加intent filters。它们允许深入链接到您的任何活动中的内容。例如,用户可以点击深层链接以查看购物应用中的页面,该页面描述用户正在搜索的产品。举例来说,当用户在其他应用或网页中点击了广告时,使用了Deeplink的商家APP,可以直接跳转到相应商品的界面;而没有使用Deeplink的APP,就只能跳转到首页。包括新闻APP的推送等等。

  • 解决方法一:在至少一个activity的intent-filter中添加
  • 解决方法二:忽略警告——在app的build.gradle中添加下列代码:
lintOptions {  
        disable 'GoogleAppIndexingWarning'  
} 

5.Design editor is unavailable until a successful build

  • 解决方法:Android Studio > Build > Clean Project;File > Sync Project with Gradles Files

6.当直接修改了Android studio的配置文件,但配置文件没有生效或遇到一些莫名其妙的问题时,可以尝试清除缓存在重启Android studio。例如:The layout in layout has no declaration in the base layout folder; this can lead to crashes when the resource is queried in a configuration that does not match this qualifier

  • 解决方法:File-》Invalidate caches/Restart-》Invalidate and Restart

7.This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints

  • 点击红色圈住的魔法棒,会多出两行代码,问题解决,参考链接,高赞的方法在ASv3以上不可行。

Android开发问题记录_第2张图片Android开发问题记录_第3张图片

8.Permission is only granted to system app,参考链接

  • File -> Settings -> Editor -> Inspections,搜索Using system app permission,红色框处不打勾!
    Android开发问题记录_第4张图片

9.为什么要签名?参考文章

10.打包遇到V1(Jar Signature)、V2(Full APK Signature)的问题,参考文章

  • v2的好处:安全,加快验证安装速度
  • 一般都勾选

11.创建Activity时Activity和AppCompatActivity的区别

  • 主要是解决安卓系统碎片化带来的兼容性问题,参考文章

12.连接ADB显示无授权,参考文章

13.打开外部工程可能会遇到的问题,参考文章

14.resource style/Theme.AppCompat.Light.DarkActionBar not found

在res/values/styles下可以看到出错的代码

失败的尝试:在File-》Project Structure下给模块添加库依赖,结果报错:The package is not available:package id extras...

Android开发问题记录_第5张图片

正确的解决方法:在模块的Build文件中添加以下代码

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

Android开发问题记录_第6张图片

15.导入其他项目的模块后运行报错!

Android开发问题记录_第7张图片

解决方法:删除出错的模块下的build文件夹,rebuild整个project!参考文章
Android开发问题记录_第8张图片

16.创建SQLite数据库文件后,在AS的Device File Explorer中可以找到文件,但在真机中找不到数据库文件

原因:目录权限问题

解决方法:root!参考文章

17.终止线程的方法:设置flag控制while循环,从而控制while循环中的run()方法

18.Split lib_main was defined multiple times

解决方法:setting中关闭instant run,参考文章

19.Error:不允许有匹配 "[xX][mM][lL]" 的处理指令目标

解决方法:复制粘贴AndroidManifest.xml文件的内容或者Ctrl+Shift+F 格式化了一下文件的内容

20.AndroidManifest.xml提示设置allowBackup属性,true or false?

解决方法:为了安全,一般选false,参考文章

21.使用Android SDK离线文档,参考文章

步骤:setting-》Android SDK-》勾选Documentation for Android SDK,等待安装

安装完成后,可以在../sdk/doc/reference目录下找到离线网页文档index.html,用浏览器打开即可!

22.布局中margin和padding的区别

  • margin对外,padding对内。参考文章

23. .9图的使用,参考文章

24.setBackground(),setBackgroundResource(),setBackgroundColor(),setBackgroundDrawable()的区别,参考文章

25.Installation failed with message Invalid File,参考文章

问题所在:instant run

解决方法一:在设置中关闭instant run即可:菜单栏Help,Find Action,输入instant run,关闭instant run
Android开发问题记录_第9张图片

解决方法二:instant run 这么好用的功能,还是开着好。可以在菜单栏Build中Clean Project-》Build APK,再重新运行即可。

26.小米手机中无法使用instant run的问题

解决方法:在开发者选项中,取消MIUI优化的功能,重新运行后即可。

27.Android AndroidManifest.xml文件的android:supportsRtl属性,参考文章

28.手机研发中看手机是user版本还是userdebug或是eng版本,参考文章

29.Android Studio打包时候报错:app:lintVitalRelease,参考文章

30.Android 6.0及以上(sdk>=23)扫描WiFi列表,getScanResults为空,

解决方法:在AndroidManifest.xml中添加权限

并在代码中检测有没有开启GPS定位:

LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
 if(!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
    // 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
}

31.Android报错installation failed with message invalid file,参考文章

$ adb install-multiple -r -t D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_4.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\dep\dependencies.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_1.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\resources\instant-run\debug\resources-debug.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\dep\dependencies.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_9.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_1.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_3.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_7.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_9.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_7.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_3.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_5.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_0.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_5.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_8.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_8.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_2.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_6.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_4.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_2.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_6.apk D:\CS\Android Developing\Projects\SensorDemo\app\build\intermediates\split-apk\debug\slices\slice_0.apk D:\Android Developing\Projects\SensorDemo\app\build\intermediates\instant-run-apk\debug\app-debug.apk 
$ adb shell pm uninstall com.lee.sensordemo
Unknown failure: Exception occurred while executing:
java.lang.IllegalArgumentException: Unknown package: com.lee.sensordemo
at com.android.server.pm.Settings.isOrphaned(Settings.java:4307)
at com.android.server.pm.PackageManagerService.isOrphaned(PackageManagerService.java:21738)
at com.android.server.pm.PackageManagerService.deletePackageVersioned(PackageManagerService.java:18500)
at com.android.server.pm.PackageInstallerService.uninstall(PackageInstallerService.java:737)
at com.android.server.pm.PackageManagerShellCommand.runUninstall(PackageManagerShellCommand.java:1486)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:193)
at android.os.ShellCommand.exec(ShellCommand.java:103)
at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:21997)
at android.os.Binder.shellCommand(Binder.java:629)
at android.os.Binder.onTransact(Binder.java:527)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2834)
at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:4023)
at android.os.Binder.execTransact(Binder.java:726)
Error while Installing APKs

解决方法:

1.点击工具栏→→Build中的Clean Project 
2.点击工具栏→→Build中的Rebulid Project 

32.Android studio 打开monitor 出现error提示

Android开发问题记录_第10张图片

解决方法:降低jdk版本,参考文章

33.Android 6.0以上getScanResult返回结果为空

解决方法:开启位置权限,参考文章

34.打Log

Android开发问题记录_第11张图片

35.魅族手机调试无法显示Log

找到手机设置-->辅助功能-->开发者选项-->性能优化-->高级日志输出-->全部允许

36.修改app图标

方法一:在drawable中加入图标图片,在AndroidManifest.xml中将图标引用指向目标图片

方法二:https://blog.csdn.net/sinat_41924085/article/details/80514151

https://blog.csdn.net/hou09tian/article/details/80388974

https://blog.csdn.net/ys743276112/article/details/51910874

37.免root ADB命令卸载系统预装应用

https://www.jianshu.com/p/e9434e7f86ea

 

你可能感兴趣的:(Android开发)