Ollie C
Ollie C

Reputation: 28519

Android build - "duplicate class: com.myapp.R"

I'm stumped by this build error. It appears it may be related to using AppCompat, as if I remove that dependency from the build file the build error is no longer present. I am not using product flavors, and actually this project is very simple indeed - one Android module, a few classes and some resources. I'm using the Android Studio beta, 0.89 (latest).

I searched the source tree and can see two files called R.java, one in the app namespace the other in the AppCompat namespace.

Related is a second build error: "duplicate class: com.myapp.BuildConfig.java

Searching reveals only one file with that name in the project.

What does this build error mean, and how do I fix it?

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "com.myapp"
    minSdkVersion 15
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.0.0'

}

Upvotes: 2

Views: 2910

Answers (1)

hiphopopotamus
hiphopopotamus

Reputation: 43

I would try deleting your R.java file, and then rebuilding the project.

If that doesn't work, try doing this.

  1. Delete the "gen", "target" and "out" folders
  2. Revert the changes within the "ipr" and "iml" files (or just delete them all, maybe even .idea folder)
  3. Start IntelliJ 12
  4. Open the pom file
  5. Right click -> "Maven" -> "Reimport"
  6. "Build" -> "Rebuild project"

Upvotes: 1

Related Questions