AS调试以及使用过程中遇到的问题记录

目录

目录

问题1:文件乱码

问题2:编译问题 Invoke-customs are only supported starting with Android O (--min-api 26)

问题3:Unknown attribute android:layout_width

问题4:CLEARTEXT communication to fyq.fangyinqing.com not permitted by network security policy

问题5  Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK

问题6:EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@1eb8354f。。。

问题7:WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.It will be removed at the end of 2019.

问题8:Manifest merger failed with multiple errors, see ?

问题9:gradle报错:buildOutput.apkData must not be null

问题10:unable to access 'https://github.com/wwqby/Myapplication.git/': SSL certificate problem



参考资料 AS的设置


问题1:文件乱码

https://blog.csdn.net/qq_28808627/article/details/50207643

正常的代码文件变成了下面打开的样子

clean,rebuild,invalidate cashes都试过了,直到发现了下面的提示

下面是解决过程

首先设置编译器的编码格式,as一般默认的UTF-8格式

然后开始修改我们的文件,用Notepad++打开,另存为UTF-8,并覆盖。

(不要用记事本打开另存为UTF-8,在window系统中,默认的实现是UTF-8-BOM格式,编译器会编译警告    非法字符: '\ufeff')

 

这个时候,as中就能正常显示了

ps:但是实际上,只是重新保存覆盖文件,不改动编码格式,一样能正常显示

最新的解决办法

有可能是as无法正常解析文件导致。直接备份项目,然后,删除项目中的资源文件,然后手动粘贴添加,重新读取,文件就可用了

可选方法:试一试清除缓存重启,

- 删除.idea文件夹,重新编译,删除打开记录,重新打开

- 修改builde.gradle文件,按照AS的同步提示重新编译工程

问题2:编译问题 Invoke-customs are only supported starting with Android O (--min-api 26)

这是因为又可能第三方库使用了lmda表达式,所以需要在build.gradle文件中添加代码,强制用java1.8编译,但是会导致出现告警(强制使用lmda表达式)(编译通过后,可以删除,重新编译就可以正常通过)

compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
  }

问题3:Unknown attribute android:layout_width

我尝试过网上推荐的方法,有时候有效,有时候无效

  • 清洁构建和重建
  • 删除.idea文件
  • 无效的高速缓存/重新启动..选项
  • 打开省电模式。

后来在overflow上找到了两个方法

1.删除android sdk,重新下载或者更换新的sdk路径

2.清除以下路径的缓存,这个方法比下载sdk要快一些

c:\Users\<user>\.gradle\caches\
c:\Users\<user>\.AndroidStudio3.2\system\caches\

问题4:CLEARTEXT communication to fyq.fangyinqing.com not permitted by network security policy

原因,在android P版本(28以后),不允许http明文协议,如果采用http通信,会给出上面的告警

解决方法

博客

build.gradle文件中,targetSdkVersion 降级

服务端和客户端网络用https通信

单独配置网络,操作如下

在 res 下新建一个 xml 目录,然后创建一个名为:network_security_config.xml 文件 ,该文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

然后在 AndroidManifest.xml application 标签内应用上面的xml配置:

  <application
        android:name=".App"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:theme="@style/AppTheme"></application>

更多android 9 适配,参考Android9.0适配和新特性大全及升级实践

 

问题5  Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK

出现原因,我通过以下代码来启动活动

getApplicationContext().startActivity(intent);

后来发现,通过context来启动活动都有可能报错

通过查看源码,

public abstract void startActivity(@RequiresPermission Intent intent);实际调用下面的函数
public abstract void startActivity(@RequiresPermission Intent intent,
        @Nullable Bundle options);

文档说明如下

Note that if this method is being called from outside of an {@link android.app.Activity} Context, then the Intent must include the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because, without being started from an existing Activity, there is no existing task in which to place the new activity and thus it needs to be placed in its own separate task.

请注意,如果从@link android.app.activity上下文外部调用此方法,则意图必须包括@link intent flag activity _new task launch标志。这是因为,如果没有从现有活动开始,现有就没有要放置新活动的任务,因此需要(新建任务)将其放置在自己的单独任务中。

因此,只要给intent加上新的flag即可

                intent.setAction("com.zy.office_system.action.sign");
                intent.setFlags(FLAG_ACTIVITY_NEW_TASK );
                getApplicationContext().startActivity(intent);

问题6:EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@1eb8354f。。。

起因,由于系统重装,在备份了个人配置文件,gradle文件和sdk文件后,本来以为能正常使用,结果每次编译,都提示这个错误,重装,清理内存,都没有用

百度问题,只有少量的文章显示,是带Android字段的插件,需要插拔后,重新启动AS,尝试后无效,可能不是这个问题

最后,发现是由于没有指定jre导致

下图中红色边框中的选项

 

问题7:WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
It will be removed at the end of 2019.

这个主要是由于引用的第三方库,引用了即将废弃的api,编译时触发的警告

解决办法,等第三方库更新,及时更新引用的版本,

或者把项目根目录下的gradle文件中,gradle插件降低为3.2.0以下。

 dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
}

问题8:Manifest merger failed with multiple errors, see ?

解决办法 来自朱家义

知乎帖子网址

在这个界面,向上滚动,就可以看到gradle编译时出错的详细原因或者文件地址,然后就可以针对性的解决了

 

问题9:gradle报错:buildOutput.apkData must not be null

 

出现情景:在真机上调试安装程序,gradle报错:buildOutput.apkData must not be null

此前刚刚升级as完成

解决办法来源

https://stackoverflow.com/questions/54503325/cause-buildoutput-apkdata-must-not-be-null

直接点击build按钮中的clean选项,然后rebuild,重新安装完成

问题10:unable to access 'https://github.com/wwqby/Myapplication.git/': SSL certificate problem

https://help.github.com/articles/changing-a-remote-s-url/

无法验证帐号密码证书

解决办法

https和ssh登录切换,切换回来会要求重新验证

或者重启AS

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值