Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Active Android is not working with gradle 2.0?

I am using Active Android in my app. It was working fine till I upgraded my Android Studio to 2.0 from 1.3. With this upgrade my gradle also got upgraded to 2.0 which is causing some issue with the Active Android.

I am getting this error when building with gradle 2.0.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.activeandroid.TableInfo.getTableName()' on a null object reference
                                                                       at com.activeandroid.Cache.getTableName(Cache.java:156)
                                                                       at com.activeandroid.query.From.addFrom(From.java:169)
                                                                       at com.activeandroid.query.From.toSql(From.java:250)
                                                                       at com.activeandroid.query.From.execute(From.java:298)

I tried building my old studio with gradle 1.3 it is still working fine. Any help please?

build.gradle file when app is giving the above error

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        classpath 'com.google.gms:google-services:2.0.0-beta2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle when app is working fine

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.google.gms:google-services:2.0.0-beta2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

gradle wrapper properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
like image 235
Rohan Arora Avatar asked Apr 08 '16 02:04

Rohan Arora


People also ask

What is the latest Gradle version for Android?

0 (May 2022) Android Gradle plugin 7.2. 0 is a major release that includes a variety of new features and improvements.

Does Gradle support java8?

Android Gradle plugin 3.0. 0 and later support all Java 7 language features and a subset of Java 8 language features that vary by platform version. When building your app using Android Gradle plugin 4.0. 0 and higher, you can use a number of Java 8 language APIs without requiring a minimum API level for your app.

Does Android use Gradle?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


2 Answers

I ran into this problem too, I found it's only an issue on Android 23+ devices, and it can be avoided if you turn Instant Run off (File->Settings->Build, Execution, Deployment->Instant Run).

If you want to keep Instant Run you can try UnChecking "Restart Activity on Code Changes"

On Mac:

Preferences > Build, Execution, Deployment > Instant Run > Uncheck "Restart Activity on Code Changes"

like image 99
Aaron Y Avatar answered Oct 09 '22 04:10

Aaron Y


There is a problem with ActiveAndroid which is not being able to retrieve the Model classes searching in the DexFile when Instant run is activated Some info about DexFile and Instant run here

There are three possible workarounds:

  1. Disable Intant run Android Studio -> Preferences -> Intant run
  2. Add the already suggested code in AndroidManifest:
<meta-data
    android:name="AA_MODELS"
    android:value="com.myapp.model.Item, com.myapp.model.Category" />
  1. Add the following code in the ActiveAndroid intialization:
Configuration.Builder config = new Configuration.Builder(this);
config.addModelClasses(Model1.class, Model2.class);
ActiveAndroid.initialize(config.create());

Hope it helps

like image 39
VictorG Avatar answered Oct 09 '22 04:10

VictorG