Android bug解決筆記

#####剪裁

系統自帶的

public void startPhotoZoom(Uri uri, Uri uritempFile) {

Intent intent = new Intent("com.android.camera.action.CROP");

intent.setDataAndType(uri, "image/*");

// 設置裁剪

intent.putExtra("crop", "true");

// aspectX aspectY 是寬高的比例

intent.putExtra("aspectX", 1);

intent.putExtra("aspectY", 1);

// outputX outputY 是裁剪圖片寬高

intent.putExtra("outputX", 200);

intent.putExtra("outputY", 200);

intent.putExtra("scale", true);// 去黑邊

intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

intent.putExtra("noFaceDetection", true);

intent.putExtra(MediaStore.EXTRA_OUTPUT, uritempFile);

?intent.putExtra("return-data", false);

startActivityForResult(intent, UtilConstants.ZOOM_CROP_WITH_DATA);

}

是沒錯,小米4 就是不干

無法保存剪切過的圖片。

查閱了 N 多。最后注釋了一條,畫線那條好了!!!

說是,原來系統默認剪切的有返回數據有個大小限制,但是小米剪切的沒有大小限制,所以往往剪切大的超過大小限制了。。。

今天又遇到了個問題

vivo X5 無法更換,拍照,相冊都不行?

什么鬼??以前我記得還是好好的!!!

排查了一下,剪切過的圖片沒有保存,為毛?

對比了一下發現,臥槽 和以前僅僅是 新的文件名(uritempFile) 用的dateFormat

原來是

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");

經實驗修改后沒問題的為:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");

你沒看錯,就是一個空格搞得鬼。。



Expected?resource?of?type?color

在真機測試正常,但是打包失敗

Expected?resource?of?type?color?[ResourceType]?。


RadioButton rb = new RadioButton(context);? ?

rb.setTextColor(context.getResources().getColorStateList(R.drawable.tab_text_checkee));

解決辦法1:

在build.gradle文件中增加一下信息:

? ? android {lintOptions {disable "ResourceType"}}

但是,這只是禁用資源類型檢測,這樣在打包過程中就不會因為資源類型不匹配而提示錯誤了。

? 根本原因是把資源類型弄錯了,總的來說這是我的不規范編程導致的,上面是設置textcolor,那說明使用一個color資源,單色值的應該來源于colors.xml中定義的,但是我上面是使用的一個colorstate,是一個自定義的selector,一個xml文件,這個時候我們應該把這個文件放在res/color目錄中,而不是res/drawable目錄中,然后使用R.color.xxx去引用,這樣就沒問題了。

? ? res/color/:存放定義了顏色狀態列表資源(ColorState List Resource)的XML文件。


強制使用相同版本的庫

更新IDE -Android Studio2.3 ,Android SDK及SDK toolos

Android Support Repo 38-->47.

編譯一下, what a fuck.

絢爛的紅提示我出錯了...

大概是這個樣子:

? ? Manifest merger failed : Attribute meta-data# support.VERSION@value value=(25.3.0) from [com.android.support:support-v13:25.3.0]

? ? AndroidManifest.xml:27:9-31 is also present at [com.android.support:preference-v7:26.0.0-alpha1]? ?

? ? AndroidManifest.xml:24:9-38 value=(26.0.0-alpha1). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:25:5-27:34 to override.

google 一下.

地址:

http://stackoverflow.com/questions/42949974/android-support-repo-46-0-0-with-android-studio-2-3

重點是:


? ? What's the problem

? ? Some libraries depend on version "X or newer" of Android support libraries so Gradle dependency resolution grabs whatever is the newest available ignoring you actually have a precise version specified in your?dependencies


? ? block.

? ? This is not what you want. You want all support libraries with same version and major version has to match compile SDK version.

? ? What's the solution

? ? Fortunately you can force a specific support library version.

? ? Put this at the end of your app module?build.gradle:

? ? configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.0' } } }}

? ? Of course replace the version with whatever it is you're using.

? ? Version values for support libraries in?dependecies

? ?block are now irrelevant.

重點在這里,強制使用相同版本的庫:

在moudle 的build.gradle中 添加上,版本自選.

? ? configurations.all {

? ? resolutionStrategy.eachDependency { DependencyResolveDetails details ->

? ? ? ? def requested = details.requested

? ? ? ? if (requested.group == 'com.android.support') {

? ? ? ? ? ? if (!requested.name.startsWith("multidex")) {

? ? ? ? ? ? ? ? details.useVersion '25.3.0'

? ? ? ? ? ? }

? ? ? ? }

? ? ? }

? ? }

? Error:Execution failed for task ':leancloudchatkit:processDebugAndroidTestManifest'.

> Manifest merger failed : uses-sdk:minSdkVersion 11 cannot be smaller than version 14 declared in library [com.android.support:appcompat-v7:26.0.0-alpha1] C:\Users\Administrator.SC-201606141054\.android\build-cache\b3d308ef34ad14838b4f9d11338a057d9ccaf6f1\output\AndroidManifest.xml

Suggestion: use tools:overrideLibrary="android.support.v7.appcompat" to force usage

還好相對簡單,意思是 最低 minsdk 不能小于support:appcompat-v7:26.0.0-alpha1所支持的,

果然在 其他library 中最低是11.修改之搞定.


極光推送

二次開發已有項目,之前的 很多東西都是比較老的,切換新的編譯版本 23記下兩個坑:

1. API23 Android 6.0 通知圖標不顯示

解決辦法:要在res下加一個極光推送圖標,文件名為jpush_notification_icon.png,圖標要求跟Android6.0的通知圖標一樣。

2.Jpush [AndroidUtil] No target service !

一直無解,,最后替換了最新的jar包,clean-rebuild,

搞定。

Eclipse DDMS files not found:?

許久不用eclipse ,導入歷史項目查看,,臥槽:

DDMS files not found: ........\platform-tools\hprof-conv.exe

木有了,想想也就更新了SDK....網上直接找,

http://download.csdn.net/detail/hu5080126/7669915

此處下載一個.

但是這又是什么鬼....

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/2728246-283c5a3c1752e847.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

連這個都要實名制..

我也是醉了.

百度一下公開的 有用的拿走

http://pan.baidu.com/s/1bpoy0az



android-async-http下載失敗: HttpResponseException: Content-Type (application/octet-stream)

[loopj](https://github.com/loopj)/**[android-async-http](https://github.com/loopj/android-async-http)**

項目二次開發,更新新的MP3接口,結果無法下載MP3文件,

原來代碼

? ? AsyncHttpClient client = new AsyncHttpClient();


? ? ? ? // 獲取二進制數據如圖片和其他文件

? ? ? ? client.get(url, new BinaryHttpResponseHandler(allowedContentTypes) {

? ? ? ? ? ? int curProgress = 0;

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onSuccess(int statusCode, Header[] headers,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? byte[] binaryData) {

? ? ? ? ? ? ? ? downLoadListener.OnSuccess(binaryData);

? ? ? ? ? ? }

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onFailure(int statusCode, Header[] headers,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? byte[] binaryData, Throwable error) {

? ? //? ? ? ? ? ? ? ? Log.e("code", statusCode + error.toString());

? ? ? ? ? ? ? ? downLoadListener.onFailure();

? ? ? ? ? ? }

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onProgress(long bytesWritten, long totalSize) {

? ? ? ? ? ? ? ? super.onProgress(bytesWritten, totalSize);

? ? ? ? ? ? ? ? int count = (int) ((bytesWritten * 1.0 / totalSize) * 100);

? ? ? ? ? ? ? ? if (count != curProgress) {

? ? ? ? ? ? ? ? ? ? curProgress = count;

? ? ? ? ? ? ? ? ? ? downLoadListener.onProgress(count);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onRetry(int retryNo) {

? ? ? ? ? ? ? ? // TODO Auto-generated method stub

? ? ? ? ? ? ? ? super.onRetry(retryNo);

? ? ? ? ? ? ? ? // 返回重試次數

? ? ? ? ? ? }

? ? ? ? });

原來指定的文件類型是


? ? ? String[] allowedContentTypes = new String[]{"audio/mpeg"};

但是新的接口打錯誤信息卻顯示

? ? HttpResponseException: Content-Type (application/octet-stream) ?not allowed!

application/octet-stream 是什么?為什么被禁止了?

octet,一種計算機語言,意思是因特網標準使用八位組.

百度百科給的解釋:http://baike.baidu.com/item/octet

把這個文件類型加進去就好了.

? ? String[] allowedContentTypes = new String[]{"application/octet-stream","audio/mpeg"};

? ? }

?Eclipse。Failed to load F:\sdk\build-tools\26.0.2\lib\dx.jar

導入down 的很古老的 項目,各種報錯。


Failed to load F:\sdk\build-tools\26.0.2\lib\dx.jar

? Unknown error: Unable to build: the file dx.jar was not loaded from the SDK。

加載最新的這個 dx.jar 出問題,多方查找,有的指出是SDK版本和ADT版本不兼容引起的。

解決辦法:使用兼容版本的 dx.jar ,選擇build-tools 文件下 其他版本的dx.jar 復制到26.0.2 版本下邊。解決問題。

Dx PARSE ERROR:

? Dx unsupported class file version 52.0 ...while parsing android/annotation/SuppressLint.class

Dx 1 error; aborting

出錯原因:java 編譯器 版本和android sdk版本不匹配。

? ? ? Android 4.4以上(包括Android 4.4)才可以用1.7版本的編譯器

? ? ? 在Android 4.4以下的只能用1.5和1.6版本的編譯器,不能用1.4版本及其以下版本。

Eclipse WEB java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

........

原因:在web項目中,當Class.forName("om.mysql.jdbc.Driver");時myeclipse是不會去查找字符串,不會去查找驅動的。所以只需要把mysql-connector-java-5.1.7-bin.jar拷貝到tomcat下lib目錄就可以了。

同樣發生類似這樣的問題 還有 使用jackson-all-2.8.0.jar 時

Eclipse 服務啟動失敗 端口被占用:

![image.png](http://upload-images.jianshu.io/upload_images/2728246-d71a5be59594bb7b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

Seceral ports (8005 8080 8009) required by Tomcat V7.0 Sever at localihost are already in use.

手動去停止服務再次重啟就好了如圖:

![image.png](http://upload-images.jianshu.io/upload_images/2728246-6478316ce3bcd601.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

Android 6.0 animation-list 失效問題


再Android4.4(API 19)可以使用,但是在Android6.0(API 23)中不可以使用。

通過AnimationDrawable的文檔:

創建逐幀動畫的最簡單方法是在XML文件中定義動畫,放置在res/drawable/文件夾中,并將其設置為View對象的背景。然后,調用start()運行動畫。

所以需要調用start方法進行調用


ImageView mIvLoading = findViewById(R.id.iv_splash_loading);

((Animatable)mIvLoading.getDrawable()).start();

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容