android studio import r,Android Studio don't generate R.java for my import project

I import a project to Android Studio , but the R.java is always empty.

public final class R {

}

I have tried:

Make project,make module, remake, etc.

Project Setting-modules-sources, then add src and gen as my source folder.

But they are not take effect.

Goto File -> Settings -> Compiler now check use external build

then rebuild project

Best Solution for android studio Users :

Goto : Menu tab - > Build - > Rebuild Project

after rebuild Proj. your R.Java file problem will be solve automatically ..

I managed to regenerate R:

File->Settings->Compiler

then UNCHECK "Use in-process build"

Rebuild Project

For me the problem with the R class has been related to automatically organized imports.

As AndroidStudio has the option to allow the automatic imports, it took the wrong R class and thats why the ids have not been found and Gradle was throwing errors!

So check if the import to the R class is referencing to the one you need.

As for me, the problem was in this superfluous line:

import android.R;

Had the same problem and solved it by:

running / building the project (it was deployed to the device, in my case)

right-clicking on the Project/Module/build folder

choose: Synchronize 'build' - then i foundProject/Module/build/source/r/debug/package/R.java

Probably it was even there before the project was build, but I didn't test that.

I hope this was helpful, even though the answer comes a bit late and by now the bug with the

Settings->Compiler->[ ] Use external build

should be fixed afaik ;-)

When I was trying to add another flavour I face same situation.

I found in one of post and I gave successful try and it work. Following I did: File -> Invalidate Cached/Restart.

So, this is the latest solution if anyone get's stuck like I did today especially, for R.Java file.

If you have lost the count of:

Clean Project

Rebuild Project

Invalidate Caches / Restart

deleted .gradle folder

deleted .idea folder

deleted app/build/generated folder

checked your xml files

checked your drawables and strings

then try this:

check your classpath dependency in your Project Gradle Scripts and if it's, this:

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

then downgrade it to, this:

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

If you are facing this problem in a specific module in your project, you could try opening just that module as a project and then build it. This worked for me. It was failing to generate the R file for the module when I was trying to re-build the entire project.

Check your project package! I had brought some classes over from another project and did not notice the subtle change in the package name. See top of your AndroidManifest.xml

Did you follow steps here? First update your Eclipse ADT plugin, then export project and the import in Android Studio.

I had a lot of problems exporting a project from Eclipse (assuming that is where you are exporting from). It was much easier for me to create a new project in Android Studio, then copy over the java files, xml files, layout directories, etc, and the AndroidManifest, into the appropriate location in the new project.

If you already have an R.java file for your project, you could try just copying it over to the new project. In Android Studio the R.java file seems to reside in build/source/r/debug/your-package-name/

Dave Agaba

I found my solution here. In short make sure not only the Eclipse plugin(if you are using eclipse) is updated. Also ensure that the Android SDK Tools, the SDK platform-tools and the SDK Build-tools are updated. After this restart your machine.

Yi H.

I failed even if I tried to update the SDK tools as mentioned here.

Here is how I solved the problem (for the library projects imported).

In File -> Project Structure -> Modules, I removed the problematic projects,

and added them again by selecting New Module -> Android Library Module.

50b506ff1778f0c908d5c6a97494c75d.png

After rebuilding the project, I got all the R.java files back.

I will answer the question even though it has been a long time since it was thrown, just in case someone else get to it.

Tested on Android Studio ONLY (but I guess it could work for Eclipse as well) :

Check your build/source/r folder. In there, you should find some directories labelled under the name of your gradle build name (default : debug).

Verify that the name of the package associated with R is the one you want.

I know this trick solves the problem of switching namespace, because Android Studio (or Gradle I don't know who is responsible for that) seems not to regenerate it in that case.

I haven't tried it when importing a project from Eclipse though.

Go to File → Settings → Editor → Auto Import and at java tab you should have:

Insert imports on paste: ASK.

If you have import for ALL, then Android Studio import other file.

bcae319fc541aef2ad6dce8b0b1fa4da.png

Just use the 'Rebuild Project' from the 'Build' menu from the top menu bar.

I had a similar problem in a large multi-module project with many dependencies among the modules. What worked for me, was to attempt to build separately from command line all the modules that failed to build within Android Studio. That gave me indications on resources missing in each project. From the project level in my console I did:

$ cd moduleName

$ ../gradlew assembleDebug

This provided me with a number of 'No resource found that matches the given name' errors, that weren't shown before, when I build the project as a whole.

I had a similar problem within my project using Android Studio 1.5.1. For me, bulding the project from command line by using following command resolved the problem:

gradle assembleRelease

File->Invalide Cahces / Restart

In my case I had an empty line prior a drawable definition in xml. This was braking aapt essentially not allowing to generate R.java .

Maryam Azhdari

I had this problem after update gradle...

There are several reasons that causes the projectb9aa3b5c4cf1eeafd66cce624c926ade.png not to be built:

1-Unknown error in drawable or xml files

2-Update gradle or libraries

and etc ...

Solution :

1-Clean and rebuild project

2-Delete .idea and build folders in project file(shown in picture)

then goto "File/Invalidate catch-restart"

3-Roll back to previous gradle version and libraries.

user3440768

Go to Menu-Tab -> Project -> Build -> Automatically(check this option). and than reopen a new project.

来源:https://stackoverflow.com/questions/16622515/android-studio-dont-generate-r-java-for-my-import-project

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值