应用工作在调试/从Eclipse中运行,但.apk文件解析包含自定义视图的XML布局时给出.classNotFoundException自定义、视图、布局、文件

2023-09-13 01:21:22 作者:ち潮货↙總裁

我的应用程序的调试和运行完全正常我的目标设备(HTC Desire HD的)上,当应用程序通过USB从Eclipse的安装。

My application will debug and run perfectly fine on my target device (HTC Desire HD) when the application is installed via USB from Eclipse.

然而,当我出口到.apk文件,然后在我的Desire HD的安装这个apk文件(具有先手动卸载了previous安装我的应用程序),它崩溃。

However, when I export to .APK and then install this .APK on my Desire HD (having first manually uninstalled the previous installation of my application), it crashes.

已经考察了logcat中的错误,我可以看到一个自定义扩展查看我的,那就是在布局XML文件中使用它的完全限定名称引用,显然不能可以发现,导致 .classNotFoundException

Having inspected the error in Logcat I can see that a custom extended View of mine, that is referenced using its fully-qualified name in a layout XML file, apparently cannot be found and leads to a .classNotFoundException.

这两条线从logcat的错误跟踪感兴趣的是:

The two lines of interest from the Logcat error trace are:

04-09 21:29:01.101:E / AndroidRuntime(2157):android.view.InflateException:二进制XML文件中的行#12:错误充气类com.trevp.myAppName所致。 DashboardLayout

和进一步说明:

04-09 21:29:01.101:E / AndroidRuntime(2157):抛出java.lang.ClassNotFoundException:产生的原因com.trevp.myAppName.DashboardLayout装载机dalvik.system.PathClassLoader [/数据/应用/ com.trevp.myAppName-1.apk

当应用程序从一个导出的apk安装只有当Eclipse,安装了这个崩溃不会发生。

This crash does not occur when the application is installed from Eclipse, only when installed from an exported .APK.

在情况下,这可能是一个Proguard的问题,这是我的Proguard的配置文件。我还没有真正从默认的摸了一下,因为我是新来使用Proguard的。我的Proguard的版本是4.7。

In case this could be a Proguard issue, here is my Proguard configuration file. I haven't really touched it from default, as I'm new to using Proguard. My Proguard version is 4.7.

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

这正在膨胀的XML文件。 (合并标签的使用,因为在添加为孩子的父元素的FrameLayout

The XML file that is being inflated. (Merge tags are used because the elements within are added as children to the parent FrameLayout.)

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView   
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="top|left"
    android:scaleType="centerCrop"
    android:id="@+id/dashLayoutImage"
    android:src="@drawable/background2" android:drawingCacheQuality="high"/>

    <com.trevp.myAppName.DashboardLayout
    android:clipChildren="false"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/dashLayout"
    android:layout_gravity="top|left" />

    <include
    android:layout_gravity="top|left"
    layout="@layout/status_bar"
    android:id="@+id/statusBar" />

    <TextView
    android:layout_gravity="bottom|left"
    android:id="@+id/pollRate"
     android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    </TextView>

</merge>

在此先感谢有这方面的提示。请喊,如果有需要的任何其他提取物或配置信息。

Thanks in advance for any tips on this. Please shout if there are any other extracts or configuration information required.

推荐答案

这个问题现在已修正通过使用一个完全标准和默认 proguard.cfg 文件取自新创建的测试项目。

This problem has been now fixed by using a completely standard and default proguard.cfg file taken from a freshly created test project.

配置文件我是previously使用,引我原来的问题,是一个我必须手动添加到该项目在短时间内回来,因为它缺少。我不知道该文件来自现在 - 我最有可能用Google搜索,发现一个样品的默认文件,只是使用它。

The configuration file I was previously using, as quoted in my original question, was one that I had to add to the project manually a short time back because it was missing. I am not sure where the file came from now -- I had most probably Googled and found a sample default file and just used it.

下面是Eclipse的投入到新的项目,我来的,这使工作的apk。

Here is the one that Eclipse put into the new project for me, and that enabled a working .APK.

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*


-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

我可以看到,差异是在 -keepclass * 键入指令。

我现在会做更多的努力,以真正了解如何配置Proguard的!

I will now make more of an effort to actually understand how to configure Proguard!

为求利益,望着下面几行:

For the sake of interest, looking at the following lines:

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

这些看起来像他们在那里preserve 查看构造函数(或preserve包含它们的类),只会被调用时,类是从XML引用。

These look like they're there to preserve View constructors (or, preserve the classes that contain them) that would only be called when the class is referenced from XML.

 
精彩推荐
图片推荐