gpt4 book ai didi

Android - Proguard 和改造 2?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:06:28 25 4
gpt4 key购买 nike

我正在为我的项目使用 Proguard,下面的代码在我的 proguard-rules.pro 中:

# Retrofit
-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.james.mime4j.** { *; }
-keep class javax.inject.** { *; }
-keep class javax.xml.stream.** { *; }
-keep class retrofit.** { *; }
-keep class com.google.appengine.** { *; }
-keepattributes *Annotation*
-keepattributes Signature
-dontwarn com.squareup.okhttp.*
-dontwarn rx.**
-dontwarn javax.xml.stream.**
-dontwarn com.google.appengine.**
-dontwarn java.nio.file.**
-dontwarn org.codehaus.**

-dontwarn retrofit2.**
-dontwarn org.codehaus.mojo.**
-keep class retrofit2.** { *; }
-keepattributes Exceptions
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepattributes EnclosingMethod
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
-keepclasseswithmembers interface * {
@retrofit2.* <methods>;
}
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

# Add any classes the interact with gson
# the following line is for illustration purposes
-keep class com.example.asheq.zanis_postmans.ListAddressesActivity
-keep class com.example.asheq.zanis_postmans.ListOrderActivity
-keep class com.example.asheq.zanis_postmans.LoginActivity
-keep class com.example.asheq.zanis_postmans.SendReportsActivity
-keep class com.example.asheq.track.TrackLocationService
-keep class com.example.asheq.track.TrackLocationApplication

# Hide warnings about references to newer platforms in the library
-dontwarn android.support.v7.**
# don't process support library
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }

但是当我运行我的 apk 时,我崩溃了:

enter image description here

下面是我的 gradle:

apply plugin: 'com.android.application'
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.asheq.zanis_postmans"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'org.parceler:parceler-api:1.0.4'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.google.android.gms:play-services-maps:9.6.1'
compile 'com.google.android.gms:play-services-places:9.6.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.android.gms:play-services-base:6.5.87'
compile 'com.google.android.gms:play-services-location:6.5.87'
compile 'com.google.maps.android:android-maps-utils:0.4.4'
//compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.google.code.gson:gson:2.6.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
//compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
}

这是我的TrackLocationApplication.class:

public class TrackLocationApplication extends Application {

private static final String KEY_REQUEST_DATA_NAME = "KEY_REQUEST_DATA_NAME";

private LocationRequestData locationRequestData;
private Location startLocation;

@Override
public void onCreate() {
super.onCreate();

//checkAndSetDeviceId();
checkAndSetUserName();

if (!retrieveLocationRequestData()) {
//setLocationRequestData(LocationRequestData.FREQUENCY_MEDIUM);
setLocationRequestData(LocationRequestData.FREQUENCY_HIGH);
}
initializeDB();
}

private boolean retrieveLocationRequestData() {
String name = PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_REQUEST_DATA_NAME, null);
if (!TextUtils.isEmpty(name)) {
LocationRequestData data = LocationRequestData.valueOf(name);
if (data != null) {
locationRequestData = data;
return true;
}
}
return false;
}

public void setLocationRequestData(LocationRequestData requestData) {
locationRequestData = requestData;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
preferences.edit().putString(KEY_REQUEST_DATA_NAME, requestData.name()).apply();
}

public LocationRequestData getLocationRequestData() {
if (locationRequestData == null) {
if (!retrieveLocationRequestData()) {
setLocationRequestData(LocationRequestData.FREQUENCY_HIGH);
}
}
return locationRequestData;
}

public Location getStartLocation() {
return startLocation;
}

public void setStartLocation(Location startLocation) {
this.startLocation = startLocation;
}

public LocationRequest createLocationRequest() {
LocationRequest locationRequest = new LocationRequest();
locationRequest.setInterval(locationRequestData.getInterval());
locationRequest.setFastestInterval(locationRequestData.getFastestInterval());
locationRequest.setPriority(locationRequestData.getPriority());
locationRequest.setSmallestDisplacement(locationRequestData.getSmallestDisplacement());
return locationRequest;
}

// private void checkAndSetDeviceId() {
// if (TextUtils.isEmpty(TrackLocationPreferencesManager.getDeviceId(this))) {
// String deviceId = Utils.getUniqueDeviceId(this);
// TrackLocationPreferencesManager.setDeviceId(deviceId, this);
// }
// }

private void checkAndSetUserName() {
if (TextUtils.isEmpty(TrackLocationPreferencesManager.getUserName(this))) {
String userName = android.os.Build.MODEL;
TrackLocationPreferencesManager.setUserName(userName, this);
}
}

private void initializeDB() {
Configuration.Builder configurationBuilder = new Configuration.Builder(this);
configurationBuilder.addModelClasses(LocationData.class);
ActiveAndroid.initialize(configurationBuilder.create());
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

最佳答案

您需要保留您的模型,不要混淆它们。我看到你的模型有错误,sqlite 不能在你的模型上工作。应该是这样的:

-keep class package.to.yourmodels.** { *; }

关于Android - Proguard 和改造 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41135913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com