Java.lang.NoClassDefFoundError with all R classess when using Android library

I downloaded the source code from the library for android, compiled it, and I got a .jar file, I included it in my project, and I tried to use it, but I always get java.lang.NoClassDefFoundError, I noticed that in the jar file there are no files R $ XXX, I read this post: Android Library Import delete R and tried the solutions, but no one worked for me.

I created my own simple library and I saw that either the R files are not included in the jar, but I have to add the .class files manually using winrar, but I think I am missing something simple, I use eclipse with ADT .

Thank you all

+5
source share
1

jar, r.java, manifeast jar.

- .

android Android LIbrary, Android, .

jar, jar, java , .

getResourseIdByName (getPackageName(), "drawable", "icon" ) R.drawable.icon . getResourceIdByName::

public int getResourseIdByName(String packageName, String className, String name) {
            int id = 0;
        try {
            for (int i = 0; i < Class.forName(packageName + ".R").getClasses().length; i++) {
                if(Class.forName(packageName + ".R").getClasses()[i].getName().split("\\$")[1].equals(className)) {
                    if(Class.forName(packageName + ".R").getClasses()[i] != null)
                        id = Class.forName(packageName + ".R").getClasses()[i].getField(name).getInt(Class.forName(packageName + ".R").getClasses()[i]);
                    break;
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        return id;
    }
+7

All Articles