Android Studio don't generate R.java for my im

2020-02-23 05:35发布

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

public final class R {
}

I have tried:

  1. Make project,make module, remake, etc.
  2. Project Setting-modules-sources, then add src and gen as my source folder.

But they are not take effect.

23条回答
做自己的国王
2楼-- · 2020-02-23 06:14
File->Invalide Cahces / Restart
查看更多
一夜七次
3楼-- · 2020-02-23 06:15

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

http://developer.android.com/sdk/installing/migrate.html

查看更多
【Aperson】
4楼-- · 2020-02-23 06:16

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.

查看更多
孤傲高冷的网名
5楼-- · 2020-02-23 06:16

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.

查看更多
我想做一个坏孩纸
6楼-- · 2020-02-23 06:18

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.

查看更多
手持菜刀,她持情操
7楼-- · 2020-02-23 06:18

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.

查看更多
登录 后发表回答