compilation of Ormliteconfig file in Android studi

2020-02-07 12:34发布

问题:

Can anyone guide me how to compile OrmLiteConfigUtil file in AndroidStudio i'm new to both ormlite and Android Studio.Thanks I checked the below link.but it is still giving the ClassnotFoundException.

Checked this but it is still giving the exception

回答1:

The pdf doc of ormLite said:

You will need to run this utility locally on your development box (not in an Android device), whenever you make a change to one of your data classes. This means that right now, this must be done by hand to keep the configuration file in sync with your database classes. To run the utility you will need to use the local Java runtime environment (JRE).

Under AndroidStudio, go to "Run" menu, and select "Edit Configurations...", this will make appear an dialog, click on the green button with the plus sign to add a new Run configuration (should be in the left-top corner of the dialog), in the contextual menu you should select "Application".

Next, click on "Main class" input and select your OrmLiteConfigUtil class. In the working directory input you should select the folder where the "res" android file is placed (in the android studio file structure you should have somthing as ".../app/src/main"). Also, select the checkbox "Use alternative JRE" and select a JRE path of a Java Runtime (for me java 7 of oracle works).

finally, click on "Ok" button to save the changes, and it's ready.

create a "raw" directory in your "res" android folder, do this before of run the config.

To run the new config: right click on the file class (your OrmLiteConfigUtil extended class, the same file that you select in the "Main class" input) and select Run '...'. wait for compiler and that is all!, you should see an config file in your res/raw folder

this is some of code for my OrmLiteConfigUtil extended class:

public class DatabaseConfigUtil extends OrmLiteConfigUtil {

    // put all your database classes in this array
    private static final Class<?>[] clases = new Class[]{Vendor.class};

    public static void main(String[] args) throws SQLException, IOException {
        writeConfigFile("ormlite_config.txt", clases);
    }
}

A screenshot of my configuration runner: