Problems with finding package R when working with Android and IntelliJ projects
Answered
I'm using Intellij with 1 Android java module and an IntelliJ IDEA Java module in the same project. Module B is dependant on Module A. The Idea module references the app module via import MyAndroidPackage.
The modules have seperate run applications in the project. If I run the Idea Android app module, I get no issues. If I run the Idea module I get
java: package R does not exist
inside the Android app class named Mainactivity.java. If I remove
setContentView(R.layout.activity_main);
from the same Android class, both modules run with no problems, except the Android app no longer has any layout. I'm using a basic Android java app template, with nothing modified from creation.
My sample project:
Upload id: 2022_03_09_SHHmAQ8g129MwAX8 (file: MyApp.zip)
Please sign in to leave a comment.
Do you mean that your Java app depends on Android?
Please share a sample project to reproduce the issue: https://uploads.jetbrains.com.
No, I mean I have 2 modules, both using Java, 1 is an Android App the other is a regular Idea Java project that runs on PC. The PC app is dependant on the Android App. My sample project is:
Upload id: 2022_03_09_SHHmAQ8g129MwAX8 (file: MyApp.zip)
PC app cannot depend on Android app, you can't do that.
You will need to extract your common code into a third common module, this module cannot include any Android classes/resources. Then you can make your PC app and Android app depend on this common module.
when I try this I get another issue which is
It doesn't show any erros after I do the import, until I run and compile.
How do you make an Android App dependant on the common module? I went to File -> Project Structure -> Modules, and created a dependancy for the commonmodule. I can't get the Android App to not return an error after doing the import.
You should edit build.gradle to add dependencies between modules.
https://docs.gradle.org/current/userguide/declaring_dependencies_between_subprojects.html
I followed the instrunctions but got error
also tried adding
to settings.graddle but that didn't work either, received a syntax error message:
Sample for my graddle settings:
Upload id: 2022_03_10_6UtYVVxCwaMeWk79 (file: graddle settings.rar)
If you need help with Gradle, please ask at https://stackoverflow.com/ or at https://discuss.gradle.org/.
This support channel is IntelliJ IDEA specific.