1

I am trying to use Google AutoValue to generate HomeKey in my Android Studio project, but it does not recignose AutoValue_HomeKey() (see in the commented code below). The used gradle version: 4.10.1

My Android project is based on this example one: https://github.com/Zhuinden/simple-stack/tree/master/simple-stack-example-basic-java-fragment

Did I forgot to apply a plugin, or implemented a wrong package?

HomeKey class:

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class HomeKey extends BaseKey {
    public static HomeKey create() {

        /*
            Cannot resolve AutoValue_HomeKey()
        */
        return new AutoValue_HomeKey(); 
    }

    @Override
    protected BaseFragment createFragment() {
        return new HomeFragment();
    }
}

BaseKey class:

import android.os.Bundle;
import android.os.Parcelable;

import gamf.tankolaskonyvelo.fragment.BaseFragment;

public abstract class BaseKey implements Parcelable {
    public String getFragmentTag() {
        return toString();
    }

    public final BaseFragment newFragment() {
        BaseFragment fragment = createFragment();
        Bundle bundle = fragment.getArguments();
        if (bundle == null) {
            bundle = new Bundle();
        }
        bundle.putParcelable("KEY", this);
        fragment.setArguments(bundle);
        return fragment;
    }

    protected abstract BaseFragment createFragment();
    }
}

Project level build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {url "https://jitpack.io" }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
        classpath 'com.google.gms:google-services:3.2.1'
    }
}


allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App level build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "gamf.tankolaskonyvelo"
        minSdkVersion 20
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    androidTestImplementation('com.android.support.test.espresso:espresso-    core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.github.Zhuinden:simple-stack:1.13.4'
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

    implementation "com.google.auto.value:auto-value-annotations:1.6.2"
    annotationProcessor "com.google.auto.value:auto-value:1.6.2"
    annotationProcessor 'frankiesardo:auto-parcel:1.0.3'
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Hello, the `AutoValue_` classes should show up after you try to `Rebuild Project` the project at least once. You are not using Kotlin, so `annotationProcessor` scope should handle that as is. One thing you are missing is `clojars` repository, which is used by `auto-parcel` (IIRC). – EpicPandaForce Mar 14 '19 at 19:23
  • So try adding `maven { url "https://clojars.org/repo/" }` to your repositories – EpicPandaForce Mar 14 '19 at 19:32

1 Answers1

1

You are using annotationProcessor 'frankiesardo:auto-parcel:1.0.3' which is hosted on clojars.

So you should add the following repository to your allprojects { block in build.gradle:

maven { url "https://clojars.org/repo/" }

Then you should try to Rebuild Project.

After successful build, the classes generated by annotation processing should show up.


(if you check the repo's root build.gradle, then you see the maven repos that the samples might use:

repositories {
    google()
    mavenCentral()
    maven { url "https://clojars.org/repo/" }
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.google.com' }
    jcenter()
}

so even if the library itself is hosted on jitpack.io, the sample's dependency auto-parcel is on clojars)

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428