如何解决java.lang.NoClassDefFoundError的为com.google.android.gms.R $设置样式错误? [英] How to solve java.lang.NoClassDefFoundError for com.google.android.gms.R$styleable error?

查看:530
本文介绍了如何解决java.lang.NoClassDefFoundError的为com.google.android.gms.R $设置样式错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌地图中的一个项目,并建立它的 Android.mk 。但还是(研究天)水湿找出如何解决的NoClassDefFoundError 这崩溃的时间APK谷歌地图片段通胀发生。可以在任何里面我一个方式,它必须要解决呢? Detalization如下。

谷歌Play服务库按以下方式添加:

  #Adding classpath中谷歌播放服务类
LOCAL_CLASSPATH + = $(LOCAL_PATH)/谷歌播放services_lib /斌/
...
播放的#google服务
LOCAL_STATIC_JAVA_LIBRARIES + =谷歌播放服务\\
                                谷歌播放,services_lib
...
LOCAL_ preBUILT_STATIC_JAVA_LIBRARIES + =谷歌播放服务:林达/谷歌播放services.jar \\
                                        谷歌播放-services_lib:库/谷歌播放services_lib.jar

构建云罚款,但应用程序将引发运行时错误时,试图夸大与谷歌地图片段布局。 LogCat中

  ** ** java.lang.NoClassDefFoundError的:
java.lang.NoClassDefFoundError的:com.google.android.gms.R $设置样式
    在com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(来源不明)
    在com.google.android.gms.maps.MapFragment.onInflate(来源不明)
    在android.app.Activity.onCreateView(Activity.java:4996)
    在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
    在android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    在android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
    在android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    在android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    在android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    在com.mapsvisitor.ui.MapsFragment.onCreateView(MapsFragment.java:81)
    ...

code

 最终视图布局= inflater.inflate(R.layout.maps_layout,NULL);

布局

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / map_main
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>
        <片段
            机器人:ID =@ + ID /图
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            类=com.google.android.gms.maps.MapFragment/>
< / LinearLayout中>


解决方案

的问题是,当你使用依赖项目作为库生成JAR(谷歌播放services_lib.jar)不适合独立使用(如Java静态库)。正如而是Eclipse导出以下列方式导出>的Java> JAR文件产生与解决方案,简单的使用JAR选择的src 文件夹导出:

下面的代码片断有助于定义的 com.google.android.gms.R 并嵌套类是不可用(com.google.android.gms.R $ ATTR,com.google.android。 gms.R $颜色等):

 无效isClassesAvailable(列表<串GT;类){
    对于(字符串CL:班){
        尝试{
            的Class.forName(CL);
        }
            捕捉(ClassNotFoundException的E){
            Log.w(TAG,e.getMessage());
        }
    }
}

JAR是如何打包的依赖项目(含src文件夹类请参阅文件夹的Android的。):

如何JAR已经被包装为强大的静态库(与src和根文件夹类别查看文件夹的Android和COM下):

不过之前惯用正确的解决方案,它使用Eclipse导出光劈成为GTD。简单的重新打包谷歌播放-services_lib.jar与谷歌播放-services_lib /斌/班内容和previously presented有那些使所有资源的类可用。

I use Google Maps in a project and build it with Android.mk. But still (after days of research) cann't figure out how to solve NoClassDefFoundError which crashes the apk in time Google Maps fragment inflation is happen. Can any inside me about a way it have to be solved? Detalization is below.

Google Play Services library is added in the following way:

#Adding classpath to Google Play Services classes
LOCAL_CLASSPATH += $(LOCAL_PATH)/google-play-services_lib/bin/
...
#Google Play Services
LOCAL_STATIC_JAVA_LIBRARIES += google-play-services \
                                google-play-services_lib
...
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += google-play-services:libs/google-play-services.jar \
                                        google-play-services_lib:libs/google-play-services_lib.jar

Build goes fine but application throws runtime error when tries to inflate layout with Google Maps fragment. LogCat:

**java.lang.NoClassDefFoundError**:
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
    at android.app.Activity.onCreateView(Activity.java:4996)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    at com.mapsvisitor.ui.MapsFragment.onCreateView(MapsFragment.java:81)
    ...

Code:

final View layout = inflater.inflate(R.layout.maps_layout, null);

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_main"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:orientation="vertical">
        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.MapFragment" />
</LinearLayout>

解决方案

The problem is in that when you use dependency project as a library the generated JAR (google-play-services_lib.jar) is not suitable for independent use (as java static libraries). As solution simple use JAR generated by Eclipse export instead in the following way Export > Java > JAR file with selected src and gen folders to export:

The following snippet helps to define that com.google.android.gms.R and nested classes are unavailable (com.google.android.gms.R$attr, com.google.android.gms.R$color, etc):

void isClassesAvailable(List<String> classes) {
    for(String cl: classes) {
        try {
            Class.forName(cl);
        }
            catch (ClassNotFoundException e) {
            Log.w(TAG, e.getMessage());
        }
    }
}

How JAR is packed for dependency project (with src folder classes. See folder "android" below):

How JAR has to be packed for robust static library (with src and gen folder classes. See folders "android" and "com" below):

However before idiomatically right solution which uses Eclipse export light hack becomes the GTD. Simple repacking google-play-services_lib.jar with google-play-services_lib/bin/classes content and previously presented there ones makes all resource's classes available.

这篇关于如何解决java.lang.NoClassDefFoundError的为com.google.android.gms.R $设置样式错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆