Problems with finding package R when working with Android and IntelliJ projects

已回答

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)

0

Do you mean that your Java app depends on Android?

Please share a sample project to reproduce the issue: https://uploads.jetbrains.com.

0

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)

0

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.

0

when I try this I get another issue which is

error: package CommonPackage does not exist
import CommonPackage.Main;
         ^

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.

0

I followed the instrunctions but got error

> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve project :PC.
     Required by:
         project :app
      > No matching configuration of project :PC was found. The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:
          - None of the consumable configurations have attributes.

 also tried adding 

project(':PC').projectDir = new File(settingsDir, '..\\Library\\PC')

to settings.graddle but that didn't work either, received a syntax error message:

Illegal char <:> at index 43:

Sample for my graddle settings:

Upload id: 2022_03_10_6UtYVVxCwaMeWk79 (file: graddle settings.rar)

0

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.

0

请先登录再写评论。