Android 错误集合

1. Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

解决:

在工程的gradle.properties文件中添加以下命令:

android.enableAapt2=false

 2. java.net.ProtocolException: Unexpected status line: <html>

原因:

在网络请求的 url 地址上所带参数 password 通过 Base64.DEFAULT 加密后,带有 \n 换行符,即参数的问题导致该问题。

 解决:

通过 Base64.NOWRAP 去掉换行后,错误解决。

3. java.lang.IllegalStateException:Not allowed to start service Intent : app is in background uid UidRecord

《Android 错误集合》

Android 8.0 不再允许后台service直接通过startService方式去启动,我们需要 context.startService()替换为context.startForegroundService();

Intent i = new Intent(context, MediaPlaybackService.class);
context.startForegroundService(i, CURRENT);

MediaPlaybackService onCreate()方法 设置为前台进程:

public void onCreate() {
       super.onCreate();
      NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // notification id
    final String channelId = MusicBrowserActivity.MUSIC_NOTIFICATION_CHANNEL;
    // create notification channel
    NotificationChannel mChannel = new NotificationChannel(channelId, "MUSIC", NotificationManager.IMPORTANCE_LOW);
    mNotificationManager.createNotificationChannel(mChannel);
    // set channel id
    Notification status = new Notification.Builder(MediaPlaybackService.this).setChannelId(channelId).build();
    // start for foreground process
    startForeground(PLAYBACKSERVICE_STATUS, status);
}

4. Faild to post notification on channel "null"

NotificationChannel 是 android8.0 新增的特性,如果App的 targetSDKVersion >= 26,没有设置 channel 通知渠道的话,就会导致通知无法展示。

解决: 创建 Channel

String channelID = "1"; 
String channelName = "channel_name"; NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.createNotificationChannel(channel); Notification.Builder builder = new Notification.Builder(context); builder.setContentText(msgDesc);
builder.setContentTitle(msgTitle);
//创建通知时指定channelID builder.setChannelId(channelID); Notification notification = builder.build();

上面代码是针对android8.0,我们还要兼容低版本系统以及channel属性设置。

5. found an invalid color.         java.util.concurrentException:com.android.builder.interal.aapt.v2.Aapt2Exception: AAPT2 error

《Android 错误集合》

出现这个问题的原因是项目中引入了一个 .9 图片引起的,需要更改一下.9图片的四边的黑线(拉长或者缩短都可以)。

6. No signature of method: static org.gradle.api.java.archives.Manifest.srcFile() is applicable for argument types: (java.lang.String) values …

《Android 错误集合》

 7. Kotlin compiler: 

  Unresolved reference: BaseApplication     

   ‘onCreate’ overrides nothing

《Android 错误集合》

场景: 在 common 组件里放置 BaseApplication 或者 BaseActivity ,在其他 module 中继承出现这个问题。原因是 common 组件未配置 kotlin

解决: 在 common 的 build.gradle 最上方添加:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

 8. javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT

  导致这个问题的原因就是 密钥不对 ,要严格按照密钥的生成规则

9. Error: Program type already present:  ****** .BuildConfig

    Android studio Throwing the wrong way is because 2 module have the same package name in AndroidManifest.xml, and can modify different names. 这个问题是出现在 Android 4.x ,在Android 5.x以上就没有问题了。根本原因未探索

解决: 将相同包名中的其中一个改成其他报名

10. java.lang.IllegalArgumentException: Unknown pattern character ‘X’

  “yyyy-MM-dd’T’HH:mm:ss.SSSXXX” 使用该格式转化时间格式,出现问题 。测试:Android6.0 以及 Android4.4上均出现问题。  原因:X is available only from Nougat+.

苟且解决方案: 将 “yyyy-MM-dd’T’HH:mm:ss.SSSXXX”  改为 “yyyy-MM-dd’T’HH:mm:ss.SSS”

11. io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with.

解决:

 

//RxJava2 取消订阅后,抛出的异常无法捕获,导致程序崩溃
        RxJavaPlugins.setErrorHandler {
            LogUtil.e(it.message ?: "RxJavaError")
        }

 

    原文作者:Spiderman.L
    原文地址: https://www.cnblogs.com/aimqqroad-13/p/8795421.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞