7

I would like to define my model classes in AndroidManifest.xml file using AA_MODEL tag and disable auto search. Because currently I get errors when application starts similar to:

Couldn't create class.
    java.lang.ClassNotFoundException: android.support.v4.print.PrintHelperKitkat$1
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:204)
            at com.activeandroid.ModelInfo.scanForModelClasses(Unknown Source)
            at com.activeandroid.ModelInfo.scanForModel(Unknown Source)
            at com.activeandroid.ModelInfo.<init>(Unknown Source)
            at com.activeandroid.Cache.initialize(Unknown Source)
            at com.activeandroid.ActiveAndroid.initialize(Unknown Source)
            at com.activeandroid.ActiveAndroid.initialize(Unknown Source)
            at com.company.myapp.app.MyAppApplication.onCreate(Unknown Source)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4684)
            at android.app.ActivityThread.access$1400(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            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:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)

How to do it properly ? Can you show me example of well defined AA_MODEL tag ?

Tomasz
  • 1,406
  • 1
  • 18
  • 28

2 Answers2

13

You can define the models in your Application object. This disable model auto searching.

public class ShantApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    initializeDB();
}

protected void initializeDB() {
    Configuration.Builder configurationBuilder = new Configuration.Builder(this);
    configurationBuilder.addModelClasses(Test.class);
    configurationBuilder.addModelClasses(ShoppingList.class);
    configurationBuilder.addModelClasses(ShoppingListItem.class);
    configurationBuilder.addModelClasses(ArticleInfoModel.class);

    ActiveAndroid.initialize(configurationBuilder.create());
}

}

Dominik Suszczewicz
  • 1,469
  • 2
  • 16
  • 23
  • 1
    If you encounter this problem and you already had a custom Application on your project and ActiveAndroid, you will now inherit from android.app.Application instead of com.activeandroid.app.Application. – Jorge Garcia Nov 25 '14 at 23:21
  • 2
    What is the Configuration object here? I cant seem to figure out the correct import statement. Eclipse is suggesting import android.content.res.Configuration; which doesn't work. – mbwasi Dec 30 '14 at 16:23
  • 1
    it is com.activeandroid.Configuration – Dominik Suszczewicz Dec 31 '14 at 08:46
  • 1
    @DominikSuszczewicz I've tried the v3.0 and the v3.1 JAR of ActiveAndroid and it can't find com.activeandroid.Configuration. I'm using Android Studio. I'm extending from android.app.Application. Could you help me, please? I'd be very grateful! Thank you! – anonymous Dec 31 '14 at 10:25
  • Thanks. @DominikSuszczewicz I also dont have the Configuration class ony get com.activeandroid.ActiveAndroid, com.activeandroid.Model and com.activeandroid.QueryUtils. Are you using the jar files from GitHub or Gradle or something else? – mbwasi Jan 03 '15 at 01:52
  • 4
    Here is jar I use http://clinker.47deg.com/nexus/content/groups/public/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-20141007.143731-1.jar – Dominik Suszczewicz Jan 05 '15 at 08:47
  • 2
    @DominikSuszczewicz Thanks this works, the jars on ActiveAndroid GitHub are not the latest. – mbwasi Jan 07 '15 at 02:25
5

Using XML file in Androidmanifest file :

<meta-data
 android:name="AA_MODELS"
 android:value="your.package.ModelA,your.package.ModelB,your.package.ModelC"/>
Tomasz
  • 1,406
  • 1
  • 18
  • 28