2

I am trying to work on an Android App that I started writing with Android Studio using AIDE, but I have an issue with the project throwing an Unknown entity 'R' error in AIDE that I never saw in Android Studio. I would imagine that somehow, Android Studio uses Gradle to manage this and prevent this from being an issue, but since AIDE does not support Gradle, the project does not function properly.

What must I do to make the project work in AIDE while still maintaining compatibility with Android Studio? This seems to be an issue that others have experienced, but I have been unable to find a solution to the problem.

AIDE Project Screenshot

DaveTheMinion
  • 664
  • 3
  • 22
  • 45
  • @AimanB Running "Refresh Build" does not seem to solve the problem. – DaveTheMinion Jan 27 '16 at 02:16
  • Where are the `/build` folder and the `R`class located in the Android Studio project? – Mike M. Jan 27 '16 at 02:32
  • @MikeM. The folder is located in `/app/build` and the `R` class is located at `/app/build/generated/source/r/debug/stackoverflow/davidb/R.java`. – DaveTheMinion Jan 27 '16 at 02:39
  • Yeah, AIDE probably can't find it, as that's a different directory structure than it uses. Try deleting the entire `/build` directory, and rebuild. – Mike M. Jan 27 '16 at 02:44
  • @MikeM. Even after deleting the `/build` directory, there's still a problem, although the file is now at `/app/build/gen/stackoverflow/davidb/R.java`. – DaveTheMinion Jan 27 '16 at 02:49
  • Yep, that's where it should be. Still the same error? Try adding `import stackoverflow.davidb.R;` to your class. – Mike M. Jan 27 '16 at 02:52
  • @MikeM. Still the same error, and the `import` does not change anything. – DaveTheMinion Jan 27 '16 at 02:58
  • Are you getting an error on the `import` statement? I'm not that familiar with gradle, but check those files for anything that might be specifying a build or resource location. – Mike M. Jan 27 '16 at 03:03
  • @MikeM. Everything's all right. I made a stupid mistake with the `import` statement. Now the question is if the project will still work with Android Studio. – DaveTheMinion Jan 27 '16 at 03:18
  • I'd imagine you'd just have to rebuild in Android Studio to re-create those directories it's expecting. Nothing else really changed. – Mike M. Jan 27 '16 at 03:20
  • Yes, but I don't want to have to keep adding and removing the `import` statements. Anyway, it does not matter. I will harness the power Git to maintain two branches: one for Android Studio and one for AIDE. – DaveTheMinion Jan 27 '16 at 03:29
  • The `import` statement being there shouldn't hurt anything in AS, I would guess. – Mike M. Jan 27 '16 at 03:31
  • @MikeM. It seems to freak out about it. – DaveTheMinion Jan 27 '16 at 03:34
  • Huh, I'd've thought AS would be smarter than that. Oh well, sounds like you've got a plan all the same. – Mike M. Jan 27 '16 at 03:39
  • @MikeM. I would think so as well. Perhaps AS2 will be. Anyway, unless I find a more efficient way to do things (which I really would prefer), I will just play a game of merging back and forth between two branches as necessary. If someone has a better way, please let me know. Thank you for your help Mike. – DaveTheMinion Jan 27 '16 at 03:42
  • No problem. You still might wanna dig around in the gradle files for anything that specifies a certain build location. It'd be easier to just change that, rather than all the `import`s. Cheers! – Mike M. Jan 27 '16 at 03:59
  • @MikeM. I agree, but as I am very new to Android development, I do not yet know very much about Android Studio, AIDE, or Gradle. – DaveTheMinion Jan 28 '16 at 00:18
  • Yeah, I wish I could be more specific about what to look for, but I'm not very familiar with gradle yet myself. I think you wanna look for a `sourceSets` block, like is shown on [this page](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSetOutput.html). – Mike M. Jan 28 '16 at 00:26
  • @MikeM. I found something that could be useful, but unfortunately it is for an earlier version of Android Studio and the instructions do not seem to be applicable. https://derfshaya.wordpress.com/2013/07/17/android-studio-0-2-0-and-the-gen-folder/ – DaveTheMinion Jan 28 '16 at 01:25
  • If you can find the analogous setting in your version of AS, that sounds like what you want. You could just include the folders that AIDE uses. I can't help ya there, though. I haven't played with AS since an early beta version. – Mike M. Jan 28 '16 at 01:32
  • @MikeM. New question in hopes that somebody will know: http://stackoverflow.com/questions/35052072/change-structure-used-by-android-studio-to-create-the-gen-folder – DaveTheMinion Jan 28 '16 at 02:58

4 Answers4

4

This will happen when the applicationId does not match the package name in the app's build.gradle file.

Protean
  • 443
  • 4
  • 9
2

For me, it turned out that I was missing another error that was preventing AIDE from completing the build. It was buried at the bottom of the mass of "Unknown entity 'R'" errors. Once I fixed that , it built like a dream and auto-generated the R file like normal. Yay!

mass of errors

true error at bottom

jamesc1101
  • 185
  • 1
  • 8
1

Just add an import with R with the name of your Project. Like for example, my package name is - com.xyz.app then add an Import as import com.xyz.app.R;

Darshan
  • 4,020
  • 2
  • 18
  • 49
0

enter image description here

  • Delete the build (the one I encircled in blue ink.)
  • Open the project again and refresh build
Thinker Bell
  • 77
  • 1
  • 4