[Android] Sugar ORM is not creating tables on DB creation/migration

I was having this issue in two scenarios:

– Database creation from zero (app just installed)
– Database migration (for example from v2 to v3)

there were two tables that weren’t being created.

I discovered that they both had only one constructor, with parameters.
After adding an empty constructor, both tables were created.

public NotificationDBEntry() {
}

public ProjectDBEntry() {
}

So there are two choices to make it work:
– In classes with no constructor, it will work because the default one is the empty constructor
– In classes with a non-empty constructor, it is mandatory to add an empty constructor.

Hope this saves you time!

Advertisements

[Android] Configuring a quick test environment

In order to start writing tests for our app, one quick solution could be this one:

1.- Adding junit to our build.gradle file

dependencies{
...
testCompile 'junit:junit:4.12'
}

2.- Creating the test folder structure
This can be done with Android Studio, or directly in your file explorer (finder, nautilus, etc). Create the folder

your_app_folder/app/src/test/java/com/companyname/appname/

where the app’s package name would be com.companyname.appname (substitute by yours).

3.- Creating a sample test
Inside the recently created folder, create a file named ProjectTest.java and copy this content:

public class ProjectTest {
@Test
public void shouldCompare1To1() throws Exception {
assertEquals(1, 1);
}
}

4.- Running the tests in console
Go to terminal, move to your app’s folder and do

./gradlew test

If everything went fine, you should have a single test passing

[Android] imeOptions not working on EditText (actionNext, actionDone)

Don’t forget to add

<item name=”android:inputType”>text</item>

or

<item name=”android:inputType”>textPassword</item>

to your EditText’s style

Directly on XML:

<EditText
style=”@style/PasswordEditText”
android:id=”@+id/login_et_password”
android:layout_below=”@+id/login_tv_password”
android:inputType=”text”
android:imeOptions=”actionDone”
/>

[Marmalade SDK] Warning: Using default deployment icon(s)

I just found this error when deploying my Marmalade App to Android.

As it’s explained on this thread, we need to supply a default generic icon, apart from the android-specific icon options (like android-icon-xhdpi).

For those using the hub, there is a solution in the previously mentioned thread. For those who, like me, still use .mkb files, this is how I’ve solved it.

deployments
{
["Default"]
icon='data/icons/icon96.png'

... rest of the mkb
}

Deploy tool is not complaining about this anymore ūüôā

[Android SDK] Useful keyboard shortcuts for Android Studio

The ones I use most:

While developing

Alt+enter over class in code (.java): Quick assistance (import class, override methods, etc)
Alt+enter over string in code (.java): Extract string resource (include in res/values/strings.xml)
Alt+enter over string in resource file (.xml): Extract string resource (same as previous)

Shift+Cmd+F9: Make module (only current module)
Shift+Cmd+UP: Move this line UP (in .java)
Shift+Cmd+DOWN: Move this line DOWN (in .java)

Ctrl+R (aka ^ R): Run
Ctrl+Alt+D: Debug
Ctrl+Alt+I: Auto-indent code

Cmd+Backspace: Remove current line (VERY USEFUL)
Cmd+D: Duplicate current line (VERY USEFUL)

Cmd+F9: Make project  (all modules, app, wear, glass..)

When debugging:

F8: Step over
Cmd+Alt+R: Continue execution (what a weird shortcut this one)

I’ll keep completing it everytime I find a really useful one. Feel free to post your own in comments!

[Android SDK] Installing Gradle in command-line shell (MacOS X)

Once we install Android Studio (or just gradle itself), it is very comfortable to have it added to our PATH, which makes us able to run commands like

gradle task1

from any Android project’s folder.

One way to do that is adding gradle’s path to our PATH variable. Under¬†MacOS X, this is done with the following steps.

1.- In terminal:

export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.2.1

*We assume we’re using the bundled Gradle that comes with Android Studio. You can place gradle anywhere else, like¬†your /Users/user folder, and use this location. Example:

export GRADLE_HOME=/Users/jimmy/gradle-2.2.1

2.- Now, let’s have a look at our PATH variable. In terminal:

echo $PATH

It should look like:

/usr/bin:/bin:/usr/sbin: ... (more system folders separated by ":" )

To¬†append gradle’s folder at the end of¬†our path:

export PATH=$PATH:$GRADLE_HOME/bin

Now, execute “echo $PATH” again, and you should see gradle’s folder appended in the end, separated by a “:”.

If you were successful on step 2, you should now be able to execute:

gradle –version

And see an output like:

------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time:   ...
Build number: none
Revision:     6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.6.0_65 (Apple Inc. 20.65-b04-462)
OS:           Mac OS X 10.9 x86_64

Hope it helps!