Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Library can not use R? #17

Open
WayLoCode opened this issue Dec 27, 2017 · 8 comments
Open

Library can not use R? #17

WayLoCode opened this issue Dec 27, 2017 · 8 comments

Comments

@WayLoCode
Copy link

java.lang.NoClassDefFoundError: Failed resolution of: Lme/vigi/fataar/demo/aarLib/R$layout;
at me.vigi.fataar.demo.aarLib.AarLibActivity.onCreate(AarLibActivity.java:17)

@songnick
Copy link

songnick commented Mar 12, 2018

This plugin just copy library's jar to libs dir and merge asset、res etc;So the aarLib's R.java is not generated,then your error coming

@rusmichal
Copy link

rusmichal commented Apr 16, 2018

Did you find workaround? @WayLoCode

@nikgupta1231
Copy link

@WayLoCode did you find any solution for this?

@richfuns
Copy link

richfuns commented Jun 8, 2018

I got the same issue. Have you found any solutions? friend

@songnick
Copy link

songnick commented Jun 8, 2018

there is no solution for this problem, because the gradle plugin merge the resource and generate the R.java, so we can not resolve this problem

@richfuns
Copy link

richfuns commented Jun 9, 2018

Thanks again , got it friend @songnick

@mashahbazi
Copy link

Any workaround??

@KenChoi1992
Copy link

KenChoi1992 commented May 16, 2022

there is no solution for this problem, because the gradle plugin merge the resource and generate the R.java, so we can not resolve this problem

we can fix this problem by two ways:

  1. after merge resources, we create R.java by R.txt file, then merge all R.java to libs folder as a normal jar file;
  2. after merge classes.jar, we transform class file, replacing R.java to main module's package name, eg:
    module A's package name: com.example.a
    module B's package name: com.example.b
    main module merge module A and module B, which package is : com.example.main.
    Then all we have to do is replacing all java file's import R.java statement from
import com.example.a.R.layout;
import com.example.a.R.drawable;

to

import com.example.main.R.layout;
import com.example.main.R.drawable;

etc.

The second way is recommended, because it won't increase aar's file size.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants