我正在尝试在View的画布上制作圈子(ShapeDrawables
)的动画。该应用程序的调试版本运行没有问题。但是,发布的版本不显示圆圈或动画。我在Gradle中尝试了以下内容
apply plugin: 'com.android.application'
android {
config {
}
}
compileSdkVersion 27
defaultConfig {
applicationId "xxx.xxx.xxx"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.TestInterface.runner.AndroidJUnitRunner"
android.defaultConfig.vectorDrawables.useSupportLibrary true
}
buildTypes {
release {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable false
}
} }
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:gridlayout-v7:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2' }
我的proguard-rules.pro
-dontobfuscate
-keep class android.support.graphics.drawable.** { *; }
-keep class android.graphics.drawable.** { *; }
-keep class android.animation.** { *; }
我检查了APK分析器,以确保我的圈子(包裹ShapedDrawable
)上的getter和setter没有被混淆。我甚至使用APK分析器来生成proguard keep rules。
仅在运行发布版本时,Logcat会显示W/PropertyValuesHolder: Method getDiameter() with type null not found on target class class xxx.xxx.xxx.CircleAnimator$CirleHolder
。但我检查了APK分析器,这些都没有混淆......
添加动画的代码如下所示:
private void newCircleAnimation(){
int size = circles.size();
ObjectAnimator animator = ObjectAnimator.ofFloat(circles.get(size - newAnimationCount), "diameter", getEndSize());
animator.setDuration(getAnimationDuration());
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
CircleHolder tempCircle = (CircleHolder) ((ObjectAnimator) animation).getTarget();
// Have to check first in case it was removed with reset()
if (circles.contains(tempCircle)){
circles.remove(tempCircle);
}
animationCount--;
}
});
animator.start();
animationCount++;
}
我不确定从调试到发布版本还有什么不同。任何帮助将不胜感激。
答案 0 :(得分:0)
解决!
我的问题是使用package private
getter和setter。我将它们更改为public
。我还不确定为什么这只发生在发布中,而不是调试。
我从这里找到答案: Reflection not working on release apk