####編譯的時候遇到的問題:java
問題都是由於在子線程中請求更新UI。彈出Toast和更新UI都須要在主線程(UI thread)來完成。解決辦法: 1.用AsyncTask來實現,就不提供具體的實現代碼了 2.若是用到handler的時候:android
private Handler handler = new Handler(Looper.getMainLooper()) {//獲取主線程的looper public void handleMessage(android.os.Message msg) { }; };
3.用runOnUiThread來實現:app
activity.runOnUiThread(new Runnable() { @Override public void run() { //這是完成的操做 } });
####Android Studio混淆代碼時,出現這個問題:ide
Execution failed for task :xxxx:packageRelease Unable to compute hash of D:\asspace\xxxx\xxxx\build\intermediates\classes-proguard\release\classes.jar
在Stack Overflow上找到相似的問題:http://stackoverflow.com/questions/32437167/unable-to-compute-hash-of# 解決辦法爲:Please, read warnings in console carefully. I`ve also faced with similar issue and in my case there were warnings about processing one of third party libraries. After applying corresponding changes related with the library to proguard file, all started to work correctly。 大體意思是:請仔細閱讀控制檯警告。 我也面臨相似的問題,我遇到的問題是,對處理第三方庫的警告。應用與圖書館的ProGuard文件相關的相應更改後,一切都開始正常工做。oop
我遇到的狀況是:一樣的第三方庫被指定了兩次,修改後就能夠正常導出包了。多是高版本的 sdk 經過 proguard 混淆代碼時默認已經將 lib目錄中的 jar 都已經添加到打包腳本中,因此不須要再次手動添加。ui
####在RecyclerView的Adapter中用ButterKnife bindView出現一下錯誤:spa
java.lang.RuntimeException: Unable to inject views for com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder@52700878 at butterknife.ButterKnife.inject(ButterKnife.java:221) at butterknife.ButterKnife.inject(ButterKnife.java:184) at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder.<init>(ButterknifeCustomBaseAdapter.java:59) at com.murach.databasehomework.ButterknifeCustomBaseAdapter.getView(ButterknifeCustomBaseAdapter.java:70) at android.widget.AbsListView.obtainView(AbsListView.java:2177) at android.widget.ListView.makeAndAddView(ListView.java:1840) at android.widget.ListView.fillDown(ListView.java:675) at android.widget.ListView.fillFromTop(ListView.java:736) at android.widget.ListView.layoutChildren(ListView.java:1655) at android.widget.AbsListView.onLayout(AbsListView.java:2012) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) at android.view.Choreographer.doCallbacks(Choreographer.java:562) at android.view.Choreographer.doFrame(Choreographer.java:532) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5103) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at butterknife.ButterKnife.inject(ButterKnife.java:216) at butterknife.ButterKnife.inject(ButterKnife.java:184) at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder.<init>(ButterknifeCustomBaseAdapter.java:59) at com.murach.databasehomework.ButterknifeCustomBaseAdapter.getView(ButterknifeCustomBaseAdapter.java:70) at android.widget.AbsListView.obtainView(AbsListView.java:2177) at android.widget.ListView.makeAndAddView(ListView.java:1840) at android.widget.ListView.fillDown(ListView.java:675) at android.widget.ListView.fillFromTop(ListView.java:736) at android.widget.ListView.layoutChildren(ListView.java:1655) at android.widget.AbsListView.onLayout(AbsListView.java:2012) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) at android.view.Choreographer.doCallbacks(Choreographer.java:562) at android.view.Choreographer.doFrame(Choreographer.java:532) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5103) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.TextView at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder$$ViewInjector.inject(ButterknifeCustomBaseAdapter$ViewHolder$$ViewInjector.java:13) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at butterknife.ButterKnife.inject(ButterKnife.java:216) at butterknife.ButterKnife.inject(ButterKnife.java:184) at com.murach.databasehomework.ButterknifeCustomBaseAdapter$ViewHolder.<init>(ButterknifeCustomBaseAdapter.java:59) at com.murach.databasehomework.ButterknifeCustomBaseAdapter.getView(ButterknifeCustomBaseAdapter.java:70) at android.widget.AbsListView.obtainView(AbsListView.java:2177) at android.widget.ListView.makeAndAddView(ListView.java:1840) at android.widget.ListView.fillDown(ListView.java:675) at android.widget.ListView.fillFromTop(ListView.java:736) at android.widget.ListView.layoutChildren(ListView.java:1655) at android.widget.AbsListView.onLayout(AbsListView.java:2012) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14289) at android.view.ViewGroup.layout(ViewGroup.java:4562) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) at android.view.Choreographer.doCallbacks(Choreographer.java:562) at android.view.Choreographer.doFrame(Choreographer.java:532) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5103) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)
在stackoverflow上找到Using Butter Knife in Custom RecyclerAdapter Unable to inject views error.net
檢查View類型是否正確。線程
####Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" 一個項目Debug包,安裝在紅米NOTE 1S手機上的時候崩潰退出,查看logcat發現報「java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication"」:code
FATAL EXCEPTION: main Process: cn.hnshangyu.electricproject, PID: 2454 java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" on path: DexPathList[[zip file "/data/app/cn.XXX-2.apk"],nativeLibraryDirectories=[/data/app-lib/cn.XXX-2, /vendor/lib, /system/lib]] at android.app.LoadedApk.makeApplication(LoadedApk.java:509) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4413) at android.app.ActivityThread.access$1500(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5113) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" on path: DexPathList[[zip file "/data/app/cn.XXX-2.apk"],nativeLibraryDirectories=[/data/app-lib/cn.XXX-2, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at android.app.Instrumentation.newApplication(Instrumentation.java:975) at android.app.LoadedApk.makeApplication(LoadedApk.java:504) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4413) at android.app.ActivityThread.access$1500(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5113) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method)
查看個人代碼中並無這個類,只能是系統自帶的類,而後在網上搜索「com.android.tools.fd.runtime.BootstrapApplication」這個類在哪裏出現,發現這個類是Instant Run方法用到的,所以應該是紅米NOTE不支持 Instant Run才致使的。感謝lihenair的博客!