Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Autovalue in java module and using in Android module

Using Android Studio I have an Android Module, and a Java module. In the Java module, I want to use AutoValue to generate immutable classes.

All seems to work fine (files are generated in the Java module) but I'm unable to access those files in the Android project. Any suggestions?

app\build.gradle

apply plugin: 'com.android.application'
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':domain')
}

domain\build.gradle

plugins {
    id 'net.ltgt.apt' version '0.6'
}
apply plugin: 'java'
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.auto.value:auto-value:1.2'
    apt 'com.google.auto.value:auto-value:1.2'
}

domain/MyLocation.java

import com.google.auto.value.AutoValue;

@AutoValue
abstract class MyLocation {

    abstract String name();

    @AutoValue.Builder
    abstract static class Builder {
        abstract Builder name(String _name);
        abstract MyLocation build();
    }
}

When I build the domain module (the java module), I see that the 'AutoValue_MyLocation' file is generated here:

\domain\build\generated\source\apt\main\my\package\domain\AutoValue_MyLocation.java

However, I am not able to use the generated class anywhere in my Android module.

like image 340
Entreco Avatar asked Mar 16 '26 05:03

Entreco


1 Answers

Nevermind, by looking at the generated class I saw that it was not public, hence I could not access it in my Android Module.

To fix it, simple make the @AutoValue class public, like so

@AutoValue
public abstract class MyLocation {
    //
}
like image 93
Entreco Avatar answered Mar 17 '26 19:03

Entreco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!