Egor
Egor

Reputation: 809

Android Studio can't find application icon in the folder outside of the project

I am building a bunch of small android projects that share a lot in common. It really bothers me that I have the same resources for all projects, so I am trying to move them to a common folder. I have the following in my build.gradle file:

sourceSets {
    main {
        resources.srcDirs = ['../Common/res', 'src/main/res']
    }
}

Android studio successfully finds the resources, but when I try to build, I am getting the following manifest errors:

Error:(15) resource mipmap/ic_launcher (aka com.GraphicsEngine.SampleApp.TestApplication:mipmap/ic_launcher) not found.
Error:(15) resource style/AppTheme (aka com.GraphicsEngine.SampleApp.TestApplication:style/AppTheme) not found.

In my android manifest I have the following lines:

android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"

I tried using relative path like so

android:icon="@../Common/res/mipmap/ic_launcher"

But that does not seem to work. It looks to me that android studio does not compile the files as resources and I do not know how to tell it to do so.

Thanks!

Upvotes: 0

Views: 481

Answers (1)

Henry
Henry

Reputation: 17841

If you want to share icons/drawables between multiple projects, then you need to create an android library module and put all your reusable stuff in that. Then in all your projects just add this new module as a dependency.

You can't do things like android:icon="@../Common/res/mipmap/ic_launcher" in android. All resources has to be indexed in R, and only then you can use them.

Upvotes: 1

Related Questions