cannot access DialogStyle

前端 未结 7 2424
南旧
南旧 2021-02-12 04:10

After updating android-support library to 22.2.0 project stopped compiling.

error: cannot access DialogStyle
  class file for android.s         


        
相关标签:
7条回答
  • 2021-02-12 04:11

    Here is a couple workarounds that worked for us:

    Workaround 1 (some people see a NPE with this, some don't)

    I just found a TEMPORARY workaround... till appcompat fixes this issue:

    1. Create the following package in your project src/main/java

    android.support.v4.app

    1. Create the following new file:

    DialogFragment$DialogStyle.java

    1. Contents

      package android.support.v4.app;

      // todo remove this file when fixed in appcompat (https://code.google.com/p/android/issues/detail?id=175086)

    public @interface DialogFragment$DialogStyle { }

    Workaround 2 (bit more ugly, but less potential for a build issue)

    I found another work-around.... a bit more ugly... but has gotten us around this issue (including the NPE on the above work-around) till appcompat 22.2 is fixed.

    1. Create the following package in your project src/main/java

    android.support.v4.app

    1. Copy the Google v4 FragmentDialog.java code

    https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/app/DialogFragment.java

    1. Rename the class (to something like TempFragmentDialog). You will get a "Duplicate" class error if you don't rename the class.

    2. Any FragmentDialog, in your project, that has @Inject will need to extend your copy of the FragmentDialog (example: public class MyFragmentDialog extends TempFragmentDialog)

    0 讨论(0)
  • 2021-02-12 04:21

    Simply put, this is a bug in support library version 22.2.0

    Just upgrade to the next update 22.2.1, works like a charm.

    0 讨论(0)
  • 2021-02-12 04:23

    Try this, it resolved my issue:

    compile ('com.android.support:appcompat-v7:22.2.0') {
            exclude module: 'support-v4' }
    compile ('com.android.support:recyclerview-v7:22.2.0') {
            exclude module: 'support-v4' }
    compile ('com.android.support:cardview-v7:22.2.0') {
            exclude module: 'support-v4' }
    compile ('com.android.support:design:22.2.0') {
            exclude module: 'support-v4' }
    // and exclude support-v4 from other dependencies as well that might include it
    // finally add it, but avoid version 22.2.0...
    compile ('com.android.support:support-v4:22.1.1')
    

    There is no need to manually add the support-v4 library to your libs directory, the last import ensures that the right version is included in your project.

    BTW all of this workaround is not your fault, blame others :)

    0 讨论(0)
  • 2021-02-12 04:27

    It happens if you are using android.support.v4.app.DialogFragment. Try to use android.app.DialogFragment instead.

    0 讨论(0)
  • 2021-02-12 04:30

    Just in case to not to skip an answer: here is also a discussion about this problem https://github.com/excilys/androidannotations/issues/1435

    BTW, do you use Android Annotations in a project where this problem exists ?

    0 讨论(0)
  • 2021-02-12 04:33

    @takoli's answer works in most cases but if you have other dependencies that silently include support-v4 or if you are too lazy to explicitly exclude support-v4 everywhere here is another solution.

    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.android.support:mediarouter-v7:22.2.0'
    // Force stable version of support-v4
    compile ('com.android.support:support-v4:22.1.1') {
        force = true
    }
    

    Update:

    AndroidAnnotations released a new version 3.3.2 that resolves this issue. If you are using AndroidAnnotations update to 3.3.2 and use the 22.2.0 support libraries without forcing the old version of support-v4. For more information see this thread

    0 讨论(0)
提交回复
热议问题