Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The R classes of aar_import targets are not provided in direct dependencies's classpaths #8109

Closed
jin opened this issue Apr 22, 2019 · 8 comments
Assignees
Labels
P1 I'll work on this now. (Assignee required) team-Android Issues for Android team

Comments

@jin
Copy link
Member

jin commented Apr 22, 2019

As title.

@jin jin self-assigned this Apr 22, 2019
@jin jin added team-Android Issues for Android team untriaged labels Apr 22, 2019
@jin
Copy link
Member Author

jin commented Apr 22, 2019

Repro:

BUILD:

android_library(
    name = "my_lib",
    srcs = ["Main.java"],
    custom_package = "com.example.bazel",
    deps = [
        artifact("com.android.support:design"),
    ],
    manifest = "LibManifest.xml",
)


android_binary(
    name = "my_app",
    custom_package = "com.example.bazel",
    manifest = "AndroidManifest.xml",
    deps = [
        ":my_lib",
    ],
)

Main.java

package com.example.bazel;

class Main {

  public static void main(String[] args) {
    // does not compile
    // int MyInt = android.support.design.R.string.abc_action_mode_done;

    // compiles
    int MyInt = R.string.abc_action_mode_done; 
  }
}

Error:

ERROR: /usr/local/google/home/jingwen/code/rules_jvm_external/examples/simple/BUILD:3:1: Building libmy_lib2.jar (1 source file) failed (Exit 1)
Main2.java:9: error: package android.support.design.R does not exist
    int MyInt = android.support.design.R.string.abc_action_mode_done;
                                        ^
Target //:my_app failed to build
Use --verbose_failures to see the command lines of failed build steps.

@jin
Copy link
Member Author

jin commented Apr 22, 2019

The resources are correctly processed into a _resources.jar file:

$ jar tf bazel-out/android-armeabi-v7a-fastbuild/bin/external/maven/com_android_support_design_27_0_2_resources.jar
META-INF/
META-INF/MANIFEST.MF
android/support/design/R$anim.class
android/support/design/R$animator.class
android/support/design/R$attr.class
android/support/design/R$bool.class
android/support/design/R$color.class
android/support/design/R$dimen.class
android/support/design/R$drawable.class
android/support/design/R$id.class
android/support/design/R$integer.class
android/support/design/R$layout.class
android/support/design/R$string.class
android/support/design/R$style.class
android/support/design/R$styleable.class
android/support/design/R.class

but this jar not added to the classpaths of direct dependencies.

@jin jin added P1 I'll work on this now. (Assignee required) and removed untriaged labels Apr 23, 2019
@cgruber
Copy link
Contributor

cgruber commented Apr 23, 2019

Thanks for reproing this - you beat me to the repro case. This is exactly our issue, and the proposed fix in gerrit is correct, and works for Square internally. Thanks!

cgruber added a commit to cgruber/bazel that referenced this issue Apr 23, 2019
@jin
Copy link
Member Author

jin commented Apr 23, 2019

This will be in 0.26.

meisterT pushed a commit that referenced this issue Apr 24, 2019
…cies of aar_import targets

Fixes #8109

RELNOTES: Added support for compiling against fully qualified R classes from aar_import dependencies.
PiperOrigin-RevId: 244946625
@cgruber
Copy link
Contributor

cgruber commented Apr 24, 2019

No chance of it being cherry picked into 0.25? It's strictly a bug fix.

@jin
Copy link
Member Author

jin commented Apr 24, 2019

Cherry-picks are only for newly introduced regressions in the release.

@cgruber
Copy link
Contributor

cgruber commented Apr 24, 2019

@jin - Ack.

cgruber added a commit to cgruber/bazel that referenced this issue Apr 26, 2019
cgruber added a commit to cgruber/bazel that referenced this issue Apr 30, 2019
cgruber added a commit to cgruber/bazel that referenced this issue May 17, 2019
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
…ncies of aar_import targets

    Fixes bazelbuild/bazel#8109

    RELNOTES: Added support for compiling against fully qualified R classes from aar_import dependencies.
    PiperOrigin-RevId: 244946625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 I'll work on this now. (Assignee required) team-Android Issues for Android team
Projects
None yet
Development

No branches or pull requests

3 participants
@cgruber @jin and others