add R.txt from .AAR

1,122 views
Skip to first unread message

Vladimir Svoboda

unread,
Oct 19, 2015, 10:01:08 AM10/19/15
to Chromium-dev
Hello everybody,

I've posted many questions how to add .AAR file to Chromium, this is maybe last one :] so here's my problem:

Our .AAR contains:
folders: aapt, aidl, assets, libs, res
files: AndroidManifest.xml, classes.jar, R.txt

So I've created new target at anroid_tools.gyp, set theese values:

        'jar_path': '../cyan/cyanSmartProtection-release-logs/cyanSmartProtection-release-logs.jar',
        'has_java_resources': 1,
        'android_manifest_path': '../cyan/cyanSmartProtection-release-logs/AndroidManifest.xml',
        'resource_dir': '../cyan/cyanSmartProtection-release-logs/res',
        'R_package': 'at.cyan.smartprotection',
        'R_package_relpath': 'at/cyan/smartprotection',

Libs are included, Chromium is compiled. However when I run it, after 5-10 sec, it crashes  (after 5-10 sec is that .AAR activated on our servers) with stack trace bellow. I think it's related with that R.txt which I didn't included to .gyp target. Is here a way how to include it? Or some workaround?


Thank you! :]

D/AndroidRuntime(27779): Shutting down VM
E/AndroidRuntime(27779): FATAL EXCEPTION: main
E/AndroidRuntime(27779): Process: org.chromium.chrome, PID: 27779
E/AndroidRuntime(27779): java.lang.NoClassDefFoundError: Failed resolution of: Lat/cyan/smartprotection/R$string;
E/AndroidRuntime(27779):     at at.cyan.smartprotection.NotificationManager.refreshIcon(NotificationManager.java:117)
E/AndroidRuntime(27779):     at at.cyan.smartprotection.NotificationManager.showServiceActive(NotificationManager.java:90)
E/AndroidRuntime(27779):     at at.cyan.smartprotection.InitService.registerComponents(InitService.java:289)
E/AndroidRuntime(27779):     at at.cyan.smartprotection.InitService.access$000(InitService.java:65)
E/AndroidRuntime(27779):     at at.cyan.smartprotection.InitService$1.run(InitService.java:221)
E/AndroidRuntime(27779):     at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(27779):     at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(27779):     at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(27779):     at android.app.ActivityThread.main(ActivityThread.java:5254)
E/AndroidRuntime(27779):     at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27779):     at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(27779):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
E/AndroidRuntime(27779):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
E/AndroidRuntime(27779): Caused by: java.lang.ClassNotFoundException: Didn't find class "at.cyan.smartprotection.R$string" on path: DexPathList[[zip file "/data/app/org.chromium.chrome-1/base.apk"],nativeLibraryDirectories=[/data/app/org.chromium.chrome-1/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(27779):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(27779):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(27779):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(27779):     ... 13 more
E/AndroidRuntime(27779):     Suppressed: java.lang.ClassNotFoundException: at.cyan.smartprotection.R$string
E/AndroidRuntime(27779):         at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(27779):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(27779):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(27779):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(27779):         ... 14 more
E/AndroidRuntime(27779):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
W/ActivityManager(  558):   Force finishing activity 1 org.chromium.chrome/.browser.ChromeTabbedActivity
I/OpenGLRenderer(  558): Initialized EGL, version 1.4

Vladimir Svoboda

unread,
Oct 19, 2015, 10:22:20 AM10/19/15
to Chromium-dev
Unfortunately adding: 'R_text_file': '../cyan/cyanSmartProtection-release-logs/R.txt', didn't help...



Dne pondělí 19. října 2015 16:01:08 UTC+2 Vladimir Svoboda napsal(a):

Vladimir Svoboda

unread,
Oct 20, 2015, 7:13:32 AM10/20/15
to Chromium-dev
Or only variables:
        'has_java_resources': 1,

        'R_package': 'at.cyan.smartprotection',
        'R_package_relpath': 'at/cyan/smartprotection',

should generate at.cyan.smartprotection.R.java?  Or I need not classes.jar but it's source code to build it from scratch with Chromium build system?

Somebody? :{

Dne pondělí 19. října 2015 16:22:20 UTC+2 Vladimir Svoboda napsal(a):

Anton Vayvod

unread,
Oct 20, 2015, 8:26:26 AM10/20/15
to Vladimir Svoboda, Chromium-dev
You need to have two targets:
- a no_res target that adds the .jar file to the build
- a res target depending on the first one that adds resources

There're a few examples in third_party/android_tools/android_tools.gyp:

    {
      # This jar contains the Android support v7 appcompat library from the
      # revision 18 of the Android Support library. This library doesn't
      # contain the resources needed for the library to work.
      # TODO(avayvod): Add the resources directly once crbug.com/274697 is
      # fixed.
      'target_name': 'android_support_v7_appcompat_javalib_no_res',
      'type' : 'none',
      'variables': {
        'jar_path': '<(android_sdk_root)/extras/android/support/v7/appcompat/libs/android-support-v7-appcompat.jar',
      },
      'includes': ['../../build/java_prebuilt.gypi'],
    },

    {
      # This target contains the Android support v7 appcompat library with the
      # resources needed.
      'target_name': 'android_support_v7_appcompat_javalib',
      'type': 'none',
      'variables': {
        'java_in_dir': '<(android_sdk_root)/extras/android/support/v7/appcompat',
        'R_package': ['android.support.v7.appcompat'],
        'R_package_relpath': ['android/support/v7/appcompat'],
        'has_java_resources': 1,
        'res_v14_skip': 1,
        'run_findbugs': 0,
      },
      'dependencies': [
        'android_support_v7_appcompat_javalib_no_res',
      ],
      'includes': [ '../../build/java.gypi' ]
    },

Then also make sure proguard.flags keeps the at.cyan.protection.R

It would make it easier if you would provide more details about what you're doing, ideally in the form of a CL that would allow to reproduce the problem, but even a copy/paste of the whole modification of android_tools.gyp would be nice (not just three lines from the build rule).

Imagine the person reading the email and trying to reply is not you :)

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

Vladimir Svoboda

unread,
Oct 20, 2015, 9:08:44 AM10/20/15
to Chromium-dev, ladov...@gmail.com, ava...@chromium.org
Anton Vayvod you are awesome!!! :]

I've created it like you said and it's working!

I've missed that difference between ['../../build/java_prebuilt.gypi'] and ['../../build/java.gypi'] now I know java_prebuilt is for adding .JARs and the second one is for building .java code.

Thanks for that cool example. Thank you  Anton Vayvod. :]

So my final targets:
{
      'target_name': 'cyanSmartProtection-release-no-res',
      'type' : 'none',
      'variables': {
        'jar_path': '../cyan/cyanSmartProtection-release-logs/cyanSmartProtection/libs/cyanSmartProtection-release-logs.jar',
      },
     'dependencies': [
        '../android_tools/android_tools.gyp:android-logging',
        '../android_tools/android_tools.gyp:log4j',
        '../android_tools/android_tools.gyp:open-csv',     
          ],
     'includes': ['../../build/java_prebuilt.gypi'],
    },  
    {
      'target_name': 'cyanSmartProtection-release',
      'type' : 'none',
      'variables': {
        'java_in_dir': '../cyan/cyanSmartProtection-release-logs/cyanSmartProtection',

        'has_java_resources': 1,
        'R_package': 'at.cyan.smartprotection',
        'R_package_relpath': 'at/cyan/smartprotection',
      },
       #cyan
     'dependencies': [
        '../android_tools/android_tools.gyp:cyanSmartProtection-release-no-res',
          ],
     'includes': ['../../build/java.gypi'],
    },

Dne úterý 20. října 2015 14:26:26 UTC+2 Anton Vayvod napsal(a):
Reply all
Reply to author
Forward
0 new messages