Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import android project in Intellij IDEA/use shared resources

I have an android project in eclipse with the following structure:

|Project1
   |-src
   |-res

|Project2
   |-src
   |-res

Project2 link to source and resource of the Project1. (In Eclipse: Properties -> Java Build Path -> Source -> Link Source).

I try to import the project in the IDEA with the same structure (project will be used in the Eclipse and IDEA at a time). When importing, i encountered the following problems:

1. If i add Project1 in Dependencies for Project2 (Project Structure -> Dependencies), i receive the error when trying to run Project2:

android-apt-compiler: ...\AndroidManifest.xml:45: error: Error: Noresource found that matches the given name (at 'icon' with value'@drawable/ic_launcher')

android-apt-compiler: ...\AndroidManifest.xml:45: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name')

...

But in code (Project2) i can refer to resources from Project1 without any errors.

2. Then i tried to set in Project2 path to resources directory of Project1 (Project Structure -> Facet 'Android' -> Structure), and receive error:

android-apt-compiler: ...\res\values\dimens.xml:7: error: Resource entry activity_vertical_margin is already defined.

android-apt-compiler: ...\res\values\strings.xml:1412: error: Resource entry device_not_found is already defined.

...

3. I also tried to add res and src folder as a content root (Project Structure -> Sources), and receive notification:

Module Project1 must not contain source root "...\Project1\src". The root already belongs to module "Project2".

4. And i tried set same parametres as in step 1 and additionaly make Project1 as library (Project Structure -> Facet 'Android' -> Library module). I receive errors for Project1:

java:...\Project1\src\com...\TimeLineFragment.java:276: constant expression required java:...\Project1\src\com...\TimeLineFragment.java:276: constant expression required

for code like this:

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.action_open_dial_pad:
        mDialPadListener.openDialpad();
        return true;
    case R.id.action_delete_all:
        mObserver.onDeleteAllEventsAction();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

I have no more ideas how to import a project in IDEA. Is there any solution how to do this (for the described project structure), so in Eclipse all work fine?

like image 472
Evgeny Avatar asked Nov 01 '22 07:11

Evgeny


1 Answers

The error 3 can be corrected just by going to the Artifacts Settings, Modules, Sources tab, and you will see 2 folders called "gen" and "gen[generated]", delete "gen" by clicking on the X icon to the right of it.

Now, to use both "projects", you need to understand that what in Eclipse is a "Project" would be equivalent to what a "module" is in Intellij, so all you need to do is open one project, and then "Import Module", so you select the other "Project", this way they will be able to see each other resources and codes.

like image 127
Rafael R. S. Robles Avatar answered Nov 09 '22 12:11

Rafael R. S. Robles