java哪些类不能重复,无法解析R.java,重复类

博主使用Android Studio时遇到'duplicate class: mypackage.R'错误,尝试重建项目、重启软件、删除R.java等方法未解决。不删R.java编译无错但构建报错,删除所有库项目可构建但需依赖库。运行gradlew.bat报错找不到库。最后给出禁用自动构建、清理项目等解决办法。

I just start using Android Studio for a week and it works great for me, but when I started Android Studio today I get the error: 'error: duplicate class: mypackage.R'. I saw this error before when I used Eclipse so I tried to rebuild the project a few times and restarting Android Studio, this didn't help.

After reading some Stackoverflow questions I tried to deleted R.java and rebuild again, now I don't get any error while rebuilding. The only problem is that Android Studio cannot resolve R, so every line which uses R gets an error (project builds and run).

I also tried to delete all the R.class files but this doesn't help either. I checked if some class imports android.R, but they all don't, they just import 'mypackage.R'. I even deleted all my files and checked out a older version of my project but I still have the same problem.

Edit:

If I don't delete R.java the compiler doesn't give any error. Just when I try to build I get a lot of errors like: 'error: cannot find symbol variable button_login'. If I search the R.java file for 'button_login' I just find it. I did this with multiple errors.

Edit2:

When I deleted all the libaries the project now builds. But the problem is that I need those libaries (HTTPComponents). I added them from maven (File --> Project Structure --> Libaries --> +-sign') and added them to my settings.graddle:

buildscript {

repositories {

maven { url 'http://repo1.maven.org/maven2' }

}

dependencies {

classpath 'com.android.tools.build:gradle:0.4'

}

}

apply plugin: 'android'

dependencies {

compile files('libs/android-support-v4.jar')

compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.2.5'

compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.2.5'

//compile 'org.apache.httpcomponents-httpclient:4.2.5' doesn't work either

//compile 'org.apache.httpcomponents-httpmime:4.2.5' doesn't work either

}

android {

compileSdkVersion 17

buildToolsVersion "17.0.0"

defaultConfig {

minSdkVersion 15

targetSdkVersion 16

}

}

When I run gradlew.bat --stacktrace --info assemble I get errors that Gradle is unable to find the libaries from the maven repository. I checked the repository but they are available. http://search.maven.org/#browse%7C1628757896

解决方案

Unfortunately I run into this as well, sometimes frequently, mostly happens when I put my computer to sleep and back on while Eclipse is on. Sometimes recompiling and validating the project works.

I did find this solution online somewhere, lost the link and do not claim credits for this:

Disable auto build, and clean the project then

Right click your project -> properties -> Java Build Path -> Source -> Add Folder -> add gen and src

Then compile

If that doesn't work, try to delete the gen folder and do that process

Let me know.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值