我使用Proguard来混淆我的Android应用。
除了java.lang.NoClassDefFoundError: com.myapp.android.MediaActivity
之外,一切都很完美。
Activity
当我不使用Proguard时,Activity
工作正常。我在使用Proguard时只遇到这个问题。
我的AndroidManifest
已在Activity
上宣布,我的所有其他人-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keep class com.myapp.android.MediaActivity { *; }
-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.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
# Also keep - Enumerations. Keep the special static
# methods that are required in enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
都正常工作,我只对这一特定问题感到疑惑。
这是我的Proguard配置:
-keep class com.myapp.android.MediaActivity { *; }
正如您所看到的,我还添加了这一特定的行以尝试使其有效,但事实并非如此:
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import com.myapp.android.fragment.places.FragmentSupportPlacesBase;
import com.myapp.android.fragment.grid.BaseCursorGridFragmentSupport;
import com.myapp.android.fragment.grid.SupportScreenShotCursorGridFragment;
import com.myapp.android.fragment.grid.SupportTimelineCursorGridFragment;
import com.myapp.android.model.Place;
import com.myapp.android.model.SelectedInfo;
import java.util.ArrayList;
import java.util.List;
编辑: 以下是MediaActivity的导入:
using(var connection = new MySqlConnection(connectionString))
{
connection.Open();
using(var command = new MySqlCommand())
{
command.Connection = connection;
command.CommandText = @"INSERT INTO rookstayers (name, sex, vocation, level, achievements, world, lastlogin, accountstatus, onlinestatus) VALUES (@name, @sex, @vocation, @level, @achievements, @world, @lastLogin, @accountStatus, @onlineStatus)";
command.Prepare();
foreach(var rooker in Players)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@name", rooker.Name);
command.Parameters.AddWithValue("@sex", rooker.Sex);
command.Parameters.AddWithValue("@vocation", rooker.Vocation);
command.Parameters.AddWithValue("@level", rooker.Level);
command.Parameters.AddWithValue("@achievements", rooker.Achievements);
command.Parameters.AddWithValue("@world", rooker.World);
command.Parameters.AddWithValue("@lastLogin", rooker.LastLogin);
command.Parameters.AddWithValue("@accountStatus", rooker.AccountStatus);
command.Parameters.AddWithValue("@onlineStatus", rooker.OnlineStatus);
command.ExecuteNonQuery();
}
}
}
有没有人知道它为什么会发生以及如何解决?
答案 0 :(得分:0)
感谢antonio指出我正确的方向。
我的Activity
正在实施接口PlacesCallbacks
(无缘无故)
public interface PlacesCallbacks{
void onPlaceSelected(long quadKey, short zoomLevel);
void onPlaceSelected(Place place);
}
但是此Interface
中没有使用此Activity
,而且我的应用中的任何地方都没有使用,并且实施的方法都是空的。
所以我猜Proguard删除了这个Interface
,因为它并没有在任何地方使用,但它是在Activity
中实现的。
我所要做的只是删除Interface
。