Android 錯誤集合

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

解決:html

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

android.enableAapt2=false

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

緣由:react

在網絡請求的 url 地址上所帶參數 password 經過 Base64.DEFAULT 加密後,帶有 \n 換行符,即參數的問題致使該問題。android

 解決:api

經過 Base64.NOWRAP 去掉換行後,錯誤解決。網絡

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

Android 8.0 再也不容許後臺service直接經過startService方式去啓動,咱們須要 context.startService()替換爲context.startForegroundService();app

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

MediaPlaybackService onCreate()方法 設置爲前臺進程:ide

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 通知渠道的話,就會致使通知沒法展現。post

解決: 建立 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

出現這個問題的緣由是項目中引入了一個 .9 圖片引發的,須要更改一下.9圖片的四邊的黑線(拉長或者縮短均可以)。

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

 7. Kotlin compiler: 

  Unresolved reference: BaseApplication     

   'onCreate' overrides nothing

場景: 在 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") }
相關文章
相關標籤/搜索