Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference a style defined in an Android module using IntelliJ?

I've defined the following style in a module and I want to use it as a theme on an Activity

Android Module's styles.xml:

<resources>
    <style name="MyTheme" parent="android:Theme.Light.Panel"></style>
</resources>

Android application's AndroidManifest.xml:

 <activity android:name="MyActivity" android:theme="@style/MyTheme"> ... </activity>

I'm using IntelliJ, and I get compilation error saying

android-apt-compiler: AndroidManifest.xml:26: error: Error: No resource found that matches the given name (at 'theme' with value '@style/MyTheme').

How can I reference the style that is in the module's jar in my main application?

Thanks.

like image 983
Ron Tesler Avatar asked Jun 06 '13 08:06

Ron Tesler


2 Answers

I just fixed this issue, the project is like this:

  • you have module (moduleLib, for instance)
  • you have a module(moduleMain, for instance)
  • moduleMain depends on moduleLib, and some themes of moduleLib are referenced in moduleMain

what I did:

1.set moduleLib as Library project

(menu->Project Structures...->Modules->moduleLib->facet Android -> check the "Is Library project"

2 set the moduleMain depends on the moduleLib

2.1 go to the setting of moduleMain(the steps are similar to the previous one)

2.2 switch to the "Dependencies"

2.3 click "+", and select "module Dependency" add the moduleLib

2.4 change the "scope" to Compile(I have tried to pick up the Provided, but I can't use the theme then)

it works for me

like image 159
lucian Avatar answered Sep 28 '22 02:09

lucian


Library module's resources automatically get copied to and packed with App module, if module dependency is correctly set-up. That is: dependency on a module directory, not a jar file.

Library project's jar output does not package resources. Default android build tools don't support it.

There is special a packaging type called apklib used by maven-android-plugin that can package resources as well, but you have build with Maven to use this functionality.

like image 43
S.D. Avatar answered Sep 28 '22 02:09

S.D.