android drawables和动画没有在发布的版本中显示

问题描述 投票:1回答:1

我试图在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规则。

仅在运行Release Build时,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++;
}

我不确定调试到发布版本还有什么不同。任何帮助,将不胜感激。

android android-animation android-drawable android-proguard
1个回答
0
投票

解决了!

我的问题是使用package private getter和setters。我把它们换成了public。我仍然不确定为什么这只发生在发布,而不是调试。

我从这里找到答案:Reflection not working on release apk

© www.soinside.com 2019 - 2024. All rights reserved.