在另一台计算机上加载项目后,Android应用程序崩溃

时间:2017-03-10 18:26:02

标签: android android-studio

我已经将我的项目存储在DropBox中以便在计算机之间共享,因此我可以在楼上的笔记本电脑上工作。一切都在我的电脑上工作正常,然后我去了我的笔记本电脑上加载项目,当我试图运行它时它就崩溃了所以我放弃了并回到我的电脑上,但现在它也没有在那里工作。它工作正常,我根本没有改变任何代码。但现在我得到以下错误。

无论有多少gradle同步和更新以及我尝试的所有内容,我都无法弄清楚如何修复。除了解决这个问题之外,我怎么能在多台PC上同一个项目上工作而不打破一切?

我跑了一个Gradle Clean和Sync,但它似乎也没那么奏效。我也没有意识到我正在使用AsyncTask,所以我会看一下。

由于我不确定堆栈跟踪究竟是什么,这里是我的整个LogCat:)

03-10 14:25:41.849 4830-4830/com.mydomain.myapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-10 14:25:41.960 4830-4830/com.mydomain.myapp I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
03-10 14:25:41.961 4830-4830/com.mydomain.myapp I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
03-10 14:25:41.966 4830-4870/com.mydomain.myapp V/FA: Using measurement service
03-10 14:25:41.966 4830-4870/com.mydomain.myapp V/FA: Connecting to remote service
03-10 14:25:41.967 4830-4870/com.mydomain.myapp V/FA: Activity resumed, time: 4313744
03-10 14:25:41.977 4830-5248/com.mydomain.myapp E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
     Process: com.mydomain.myapp, PID: 4830
     java.lang.RuntimeException: An error occurred while executing doInBackground()
         at android.os.AsyncTask$3.done(AsyncTask.java:309)
         at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
         at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
         at java.util.concurrent.FutureTask.run(FutureTask.java:242)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
         at java.lang.Thread.run(Thread.java:818)
      Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{36fd80a 4830:com.mydomain.myapp/u0a17} (pid=4830, uid=10017) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
         at android.os.Parcel.readException(Parcel.java:1599)
         at android.os.Parcel.readException(Parcel.java:1552)
         at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550)
         at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778)
         at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
         at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1468)
         at android.content.ContentResolver.query(ContentResolver.java:475)
         at android.content.CursorLoader.loadInBackground(CursorLoader.java:64)
         at android.content.CursorLoader.loadInBackground(CursorLoader.java:56)
         at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
         at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
         at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66)
         at android.os.AsyncTask$2.call(AsyncTask.java:295)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
         at java.lang.Thread.run(Thread.java:818) 
03-10 14:25:41.980 4830-5250/com.mydomain.myapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

     [ 03-10 14:25:41.982  4830: 4830 D/         ]
     HostConnection::get() New Host Connection established 0x7effab5dc260, tid 4830
03-10 14:25:42.283 4830-4830/com.mydomain.myapp D/MainActivity: onAuthStateChanged:signed_out
03-10 14:25:42.314 4830-5250/com.mydomain.myapp I/OpenGLRenderer: Initialized EGL, version 1.4
03-10 14:25:42.314 4830-5250/com.mydomain.myapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
03-10 14:25:42.434 4830-4870/com.mydomain.myapp V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 469
03-10 14:25:42.435 4830-4870/com.mydomain.myapp V/FA: Using measurement service
03-10 14:25:42.435 4830-4870/com.mydomain.myapp V/FA: Connection attempt already in progress
03-10 14:25:42.436 4830-4870/com.mydomain.myapp V/FA: Activity paused, time: 4314214
03-10 14:25:42.457 4830-4870/com.mydomain.myapp D/FA: Connected to remote service
03-10 14:25:42.457 4830-4870/com.mydomain.myapp V/FA: Processing queued up service tasks: 2
03-10 14:25:42.526 4830-4830/com.mydomain.myapp W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
03-10 14:25:42.640 4830-5250/com.mydomain.myapp E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7effa40972a0

1 个答案:

答案 0 :(得分:0)

首先,在这个项目最后工作的原始计算机上,尝试使用gradle“clean”然后构建。如果这不起作用,可能意味着您上次工作后更改了代码。试着找出你改变了什么,然后撤消它。

其次,AsyncTask是许多令人头疼(和崩溃)的根源,因为它拥有对其启动的Activity的引用,但不是Activity的生命周期的一部分,因此可以在Activity之后对Activity进行操作活动已被破坏。我的建议 - 不要使用AsyncTask - 无论你使用它是什么,几乎总有一种更好的方法。在这里发布您的堆栈跟踪,我们可以帮助您找出问题所在。

就共享代码而言,使用版本控制系统。 GitHub很好,它是免费的。正确使用它还可以让您轻松地将代码回滚到最后一次工作的位置。

=====

好的,看看你从logcat发布的堆栈跟踪,我们看到了:

java.lang.RuntimeException:执行doInBackground()时发生错误 在android.os.AsyncTask $ 3.done(AsyncTask.java:309)java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java) :588)在java.lang.Thread.run(Thread.java:818)

引起: java.lang.SecurityException:权限拒绝:从ProcessRecord打开提供程序com.android.providers.contacts.ContactsProvider2 {36fd80a 4830:com.mydomain.myapp / u0a17}(pid = 4830,uid = 10017)需要android.permission.READ_CONTACTS或android.permission.WRITE_CONTACTS

因此,您似乎正在尝试访问ContactsProvider,但尚未在清单中放置READ_CONTACTS权限。