R.java is not created properly for Android Library application

I created a simple application for Android libraries in just 1 activity containing a TextView. It works fine, but when I mark it as a library and a link in another application, it gives errors when I try to get a text view using findViewById (R.id.welcome_textview).

It generated R.java, but in the second application, where I refer to the library, it does not contain the id field. This is how R.java files are created: -

Library application

    /* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.example.mylibrary;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int welcome_textview=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

The same file in another application

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.example.mylibrary;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

Where am I going wrong?

+5
source share
9 answers

, , . Layout, , . . , -.

+8

, : XML res/layout res/layout app.

+7

R - Xml, , , R , So

xml ,

, R.

+3

, , , .

styles.xml

   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

name AppThemMyLibrary, R . , .

+2

, Android, : com.example.mylibrary.

, , , R.java Android Library R.java , . , , . , R.java.

+1

# 1

compile project(':myLibProject')

build.gradle .

,

compile project(':library:myLibProject')

myLibProject .

- myLibProject ( )

( , Android Studio).

# 2

gradle build.gradle ,

task wrapper(type: Wrapper) {
    gradleVersion = '2.4'
}

.

# 3

, .

.

.

.

.

  • (Build → Clean Project)
  • (Build → )
  • ( → )
+1

, R . "icon.png", . .

0

Eclipse , R.java , ( Console).

:

[2013-01-13 00:39:18 - AppName] []\res\values-v11\styles.xml: 7: : : , 'android: Theme.Holo.Light'.

,

  • "res/values-v11"
  • "/-v14"

, , : R.Java com.example.app, com.example.lib, 2 .java, .

0

If your android library cannot resolve the R-class, this means that perhaps somewhere inside your XML library files there are some duplications with the main application module. There may be color names, line names, style names, layout names, etc. Just check all the files and folders of the xml library resources and make sure that nothing has the same name as the main application module. After that, perhaps the project will need one clean, and everything should be fine with import R.

Note. Also check out the library manifest file.

0
source

All Articles