ClassNotFoundException for a ContentProvider

后端 未结 6 1963
情深已故
情深已故 2021-01-02 01:53

I have a ContentProvider class and is declared in AndroidMenifest.xml like this:



        
相关标签:
6条回答
  • 2021-01-02 02:07

    If your app has grown large enough to require Multidexing and your app is not set up correctly as a Multidex app you will get this error. To set up your app as a multidex app, follow these directions:

    Setup multidex app

    0 讨论(0)
  • 2021-01-02 02:09

    This is an old thread, and the OP didn't have the same ContentProvider declaration as me, but I had the same exact error, so I want to share my findings, in case it helps anyone.

    For me, what caused the problem was that the ContentProvider declaration in the AndroidManifest.xml had an exported attribute set to true:

    android:exported="true"

    Removing it fixed the problem for me. (I didn't really need it)

    0 讨论(0)
  • 2021-01-02 02:12

    Proguard excludes all inherited content providers by default with this line (make sure it's in your cfg):

    -keep public class * extends android.content.ContentProvider
    

    If you have any additional inheritance you should exclude it as well or exclude your specific Content Provider class, for example:

    -keep public class org.iii.romulus.meridian.MediaSearchProvider
    
    0 讨论(0)
  • 2021-01-02 02:18

    This sounds similar to an issue I had that was caused by an issue with the ClassLoader, see here: Bizarre behaviour when using Apache Commons lib in Android

    This bug discusses an error relating to the class loader failing sometimes. The fix for me was to add this line:

    Thread.currentThread().setContextClassLoader(this.getClassLoader());

    in the constructor of the class that was calling the code that was failing.

    0 讨论(0)
  • 2021-01-02 02:20

    Ensure twice that you have correct qualified class name specified in AndroidManifest.xml, it must read something like this:

    <provider
        android:authorities="org.iii.romulus.meridian.mediasearch"
        android:name="org.iii.romulus.meridian.MediaSearchProvider">
    </provider>
    

    Notice that @name is fully qualified.

    0 讨论(0)
  • 2021-01-02 02:27

    The answers regarding proguard are incorrect. This would cause an easily reproducible error on every phone, every time, because the ContentProvider class would be completely missing. The developer clearly states that they cannot reproduce the error, meaning that the ContentProvider class is present but for some reason is not being found on one of their user's phones.

    I have the same crash reported in the market for my app. The stack traces look identical, and the error is occurring at installProvider. I have about 15 test phones in my office and none of them can reproduce this problem. Any other ideas would be appreciated.

    Fully qualified names in the manifest are only necessary if your java package names are not the same as your android package name. If a fully qualified name is not specified, the OS will automatically prepend the android package name to the class name specified in the manifest.

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