auto: Auto-Factory beta4 fails with DuplicateFileException

When I have a very minimal setup with a factory like:

public class MainActivity extends AppCompatActivity {

  @Inject MainActivity_DependencyFactory dependencyFactory;

  @Component(modules = MyModule.class)
  public interface MyComponent {}

  @AutoFactory public static class Dependency {

    public Dependency(@Provided String string) {}
  }

  @Module public abstract class MyModule {

    @Provides String provideString() {
      return "something";
    }
  }
}

With only the necessary dependencies


dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    provided "javax.annotation:jsr250-api:1.0"

    compile 'com.google.dagger:dagger:2.10'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.10'

    compile "com.google.auto.factory:auto-factory:1.0-beta4"
    compile 'com.android.support:multidex:1.0.1'
}

It works fine with beta3. However with beta4 I get a lot errors. I already cleared the cache.

Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK plugin.xml
  	File1: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.core/org.eclipse.core.contenttype/3.4.100/7052e115041d04410a4519a61307502fb7c138e6/org.eclipse.core.contenttype-3.4.100.jar
  	File2: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.equinox/org.eclipse.equinox.app/1.3.100/e7169b33d352f5ddb6eace73f5a4d29aae3b91ec/org.eclipse.equinox.app-1.3.100.jar
  	File3: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.core/org.eclipse.core.filesystem/1.3.100/37fce4f5488a21ce36021d4909acaf5687e1595e/org.eclipse.core.filesystem-1.3.100.jar
  	File4: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.equinox/org.eclipse.equinox.registry/3.5.101/eac5aeb82732847bc7f11e2b5c934004c4c7a543/org.eclipse.equinox.registry-3.5.101.jar
  	File5: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.equinox/org.eclipse.equinox.preferences/3.4.1/6770649a91266a4a17747b201723a1fea8c8a198/org.eclipse.equinox.preferences-3.4.1.jar
  	File6: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.core/org.eclipse.core.expressions/3.4.300/42b2139abd5638730db317a51949dac3b8d81492/org.eclipse.core.expressions-3.4.300.jar
  	File7: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.jdt/org.eclipse.jdt.core/3.10.0/647e19b28c106a63a14401c0f5956289792adf2f/org.eclipse.jdt.core-3.10.0.jar
  	File8: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.core/org.eclipse.core.resources/3.7.100/6c56ea28b84afe7d55de02763846e76dbfb0b689/org.eclipse.core.resources-3.7.100.jar
  	File9: /home/ph1b/.gradle/caches/modules-2/files-2.1/org.eclipse.core/org.eclipse.core.runtime/3.7.0/6658c235056134f7e86295e751129508802d71f2/org.eclipse.core.runtime-3.7.0.jar

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

provided 'com.google.auto.factory:auto-factory:1.0-beta5'
annotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta5'

works for me, +1 to mentioning this in the readme.

Thanks, it would be great if that was mentioned in the readme. It just speaks about adding a jar.

In java it seems to work but when I’m using kotlin it fails:

class MainActivity : AppCompatActivity() {

  @Inject lateinit var dependencyFactory: MainActivity_DependencyFactory

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    DaggerMainActivity_MyComponent.create()
        .inject(this)
  }

  @Component(modules = arrayOf(MyModule::class))
  interface MyComponent {
    fun inject(target: MainActivity)
  }

  @AutoFactory class Dependency(@Provided provided: String, necessary: String)

  @Module class MyModule {

    @Provides internal fun provideString(): String {
      return "something"
    }
  }
}

It just fails to build with

e: /home/ph1b/Dev/BrokenDaggerAutoFactory/app/build/tmp/kapt3/stubs/debug/de/paul_woitaschek/brokendaggerautofactory/MainActivity.java:29: error: error.NonExistentClass cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
e: 

e:         public abstract void inject(@org.jetbrains.annotations.NotNull()
e:                              ^
e:       error.NonExistentClass is injected at
e:           de.paul_woitaschek.brokendaggerautofactory.MainActivity.dependencyFactory
e:       de.paul_woitaschek.brokendaggerautofactory.MainActivity is injected at
e:           de.paul_woitaschek.brokendaggerautofactory.MainActivity.MyComponent.inject(p0)
e: /home/ph1b/Dev/BrokenDaggerAutoFactory/app/src/main/java/de/paul_woitaschek/brokendaggerautofactory/MainActivity.kt: (1, 1): Some error(s) occurred while processing annotations. Please see the error messages above.
e: /home/ph1b/Dev/BrokenDaggerAutoFactory/app/src/main/java/de/paul_woitaschek/brokendaggerautofactory/MainActivity.kt: (19, 43): Unresolved reference: MainActivity_DependencyFactory

This is how I setup my dependencies:

dependencies {
    provided "javax.annotation:jsr250-api:1.0"

    compile 'com.google.dagger:dagger:2.10'
    kapt 'com.google.dagger:dagger-compiler:2.10'

    kapt "com.google.auto.factory:auto-factory:1.0-beta4"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

take a look at: https://kotlinlang.org/docs/reference/kapt.html#non-existent-type-correction

adding that:

    kapt {
        correctErrorTypes = true
    }

fixed problem also remember to exclude guava if you don use. Anyway it would be great if you provide annotations only package

compileOnly("com.google.auto.factory:auto-factory:1.0-beta5") {
        exclude(group: 'com.google.guava')
    }

Auto factory shouldn’t be a compile dep

On Sun, Apr 16, 2017, 1:06 AM Paul Woitaschek notifications@github.com wrote:

Beta3 compiles. It’s really an empty project with the factory as the sole dependency.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/auto/issues/474#issuecomment-294333981, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEcyzt8BBDqfRry3l3MvOx9s7XVYmks5rwaHTgaJpZM4M2Ic3 .