Israel Lopez
Israel Lopez

Reputation: 1145

Android Studio ORMLite Configuration File - Could Not Find Raw Directory

Following notes from the previous question: Android Studio run configuration for ORMLite config generation

I was able to get my configuration to run this one class, but it is still failing with

Could not find raw directory

This is my source

package com.ilopez.android.machinesounds;

import com.j256.ormlite.android.apptools.OrmLiteConfigUtil;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created by User on 7/25/13.
 */
public class DatabaseConfigUtil extends OrmLiteConfigUtil {
    private static final Class<?>[] classes = new Class[]{
            RecordedSound.class,
    };


    public static void main(String[] args) throws IOException, SQLException {
        writeConfigFile(new File("G:\\MachineSoundsProject\\MachineSounds\\src\\main\\res\\raw\\ormlite_config.txt"), classes );
    }
}

My platform is windows, and I cant really figure out why it keeps failing with "could not find raw directory".

This is the command my android studio runs:

 "C:\Program Files\Java\jdk1.6.0_37\bin\java" -Didea.launcher.port=7544 "-Didea.launcher.bin.path=C:\Program Files (x86)\Android\android-studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\Android\android-studio\sdk\platforms\android-17\android.jar;C:\Program Files (x86)\Android\android-studio\sdk\platforms\android-17\data\res;C:\Program Files (x86)\Android\android-studio\sdk\tools\support\annotations.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\build\classes\debug;C:\Program Files (x86)\Android\android-studio\sdk\extras\android\m2repository\com\android\support\support-v4\13.0.0\support-v4-13.0.0.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\libs\ormlite-android-4.45.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\libs\ormlite-core-4.45.jar;C:\local\Dropbox\git\MachineSoundsProject\MachineSounds\libs\ormlite-jdbc-4.45.jar;C:\Program Files (x86)\Android\android-studio\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.ilopez.android.machinesounds.DatabaseConfigUtil

I'm using version 4.45 of ORMLite

Upvotes: 14

Views: 7650

Answers (10)

gor
gor

Reputation: 1066

Since i'v had to collect and compose the correct answer from all of the answers above, i here give you my complete solution:

  1. Put your config file (e.g "OrmliteDatabaseConfigUtil") under your Android project root package - ->app->src->java->com.your_package

  2. make sure that you have all of the import your file needs.

  3. add 'raw' directory and 'ormlite_config.txt"

  4. if you are using the ormLite guide to 'Using Table Config File'

    String configPath = "\res\raw\ormlite_config.txt";

  5. after setting al up, go to your config file, right click "run...main()" after that, if the first run wont work, go to the run section in the studio tool bar, click the little arrow and click 'Edit Configurations'. make sure the following:

a. main class - with full package name, it should auto suggest your class name.

b. Working Directory - C:\Users\...\app\src\main

c.Use classpth of Module: app

d.JRE: deafault

e. you can leav the 'make; alone - it should be there

f. thats it, it should work now.

Upvotes: 1

Omkar
Omkar

Reputation: 1553

Better option for Android: give and an absolute path of location to write file.

// Following code goes in your database configuration main method.
String ORMLITE_CONFIGURATION_FILE_NAME = "ormlite_config.txt";

/**
 * Full configuration path includes the project root path, and the location
 * of the ormlite_config.txt file appended to it.
 */
File configFile = new File(new File("").getAbsolutePath()
        .split("app" +File.separator + "build")[0] + File.separator +
        "app" + File.separator +
        "src" + File.separator +
        "main" + File.separator +
        "res" + File.separator +
        "raw" + File.separator +
        ORMLITE_CONFIGURATION_FILE_NAME);

/**
 * Pass configFile as argument in configuration file writer method.
 */
writeConfigFile(configFile);

Upvotes: 1

Lorenzo Barbagli
Lorenzo Barbagli

Reputation: 1281

You can use Android Studio with no problem, but make sure in edit configurations to select standard JDK and (important!) to modify "Working directory" by selecting the "main" folder of your android project

It should be something like: /your_workspace/your_project/app/src/main

Upvotes: 26

Ganesh Katikar
Ganesh Katikar

Reputation: 2700

  1. Right click of DBConfigUtil file and run DBConfigUtil.main();
    1. Go to Edit configuration section.
    2. Make sure your working directory is somthing like this: /home/xyz/projects/xyz_project/app/src/main
    3. Changed the JRE to JDK1.8
    4. In the before launch section remove Make.
    5. Ok

and run again DBConfigUtil file.

Note: Make sure you have res/raw/ormlite_config.txt file

Upvotes: 7

AlvaroSantisteban
AlvaroSantisteban

Reputation: 5336

Another crapy option is, if your database is very straight-forward, to create the txt file by hand. Here I leave the file created by program in a past project of mine that I used as a template for creating by hand another one in my current project:

#
# generated on 2013/08/15 05:07:12
#
# --table-start--
dataClass=com.alvarosantisteban.pathos.Event
tableName=events
# --table-fields-start--
# --field-start--
fieldName=id
generatedId=true
useGetSet=true
# --field-end--
# --field-start--
fieldName=sequence
useGetSet=true
# --field-end--
# --field-start--
fieldName=name
canBeNull=false
useGetSet=true
# --field-end--
# --field-start--
fieldName=day
canBeNull=false
useGetSet=true
# --field-end--
# --field-start--
fieldName=hour
useGetSet=true
# --field-end--
# --field-start--
fieldName=description
useGetSet=true
# --field-end--
# --field-start--
fieldName=location
useGetSet=true
# --field-end--
# --field-start--
fieldName=links
columnName=links
dataPersister=SERIALIZABLE
useGetSet=true
# --field-end--
# --field-start--
fieldName=isInteresting
useGetSet=true
# --field-end--
# --field-start--
fieldName=isDescriptionInGerman
useGetSet=true
# --field-end--
# --field-start--
fieldName=eventsOrigin
useGetSet=true
# --field-end--
# --field-start--
fieldName=originsWebsite
useGetSet=true
# --field-end--
# --field-start--
fieldName=themaTag
useGetSet=true
# --field-end--
# --field-start--
fieldName=typeTag
useGetSet=true
# --field-end--
# --table-fields-end--
# --table-end--
#################################

As I said, this is just a crappy workaround but it might help someone. :/

Upvotes: 1

Razze
Razze

Reputation: 4302

If you try to create it in Android Studio its trying to find the folder in the top most directory (where .idea is for e.g.) So if you create a directory res and within that raw, the util will be able to create the file.

Upvotes: 13

Ben Groot
Ben Groot

Reputation: 5050

I got the same error. I've forgot to add the "new File()" construction. After I've added that it still gave the same message. But then when I've rebuilt the project it was working suddenly.

To summarize what I did (MAC OSX user): - make sure you've added both ormlite-android and ormlite-core jar files to the libs dir - right click to add them as project library - copy the OrmLiteConfigUtil instructions from the ormlite instructions - make sure you use the full path and use the File class - add the raw dir in the res tree - add an empty ormlite_config.txt - create the build config

Apparently you need to do a Rebuild after every change to let them have effect.

Upvotes: 2

Matt Rowland
Matt Rowland

Reputation: 379

I'm not sure if this will help for Windows, but I couldn't get it to work in Android Studio on Mac until I put Make back into the Before Launch section of the Run configuration. Might be worth a go, to avoid the annoyance of swapping between Android Studio and NetBeans!

Upvotes: 1

Yasitha Waduge
Yasitha Waduge

Reputation: 13540

You get this error, If you haven't created raw folder inside res folder already. Just create raw folder manually inside res folder and try. This happens me in eclispse IDE in MAC.

Upvotes: 1

Israel Lopez
Israel Lopez

Reputation: 1145

I found a decent solution. Use a separate IDE (not Android Studio) to create your configuration file. In my case I used NetBeans IDE 7.3.1 and it worked just fine.

run:
Writing configurations to G:\MachineSoundsProject\MachineSounds\src\main\res\raw\ormlite_config.txt
Wrote config for class machinesoundandroidorm.RecordedSound
Done.
BUILD SUCCESSFUL (total time: 0 seconds)

Upvotes: 0

Related Questions