sweet-alert-dialog icon indicating copy to clipboard operation
sweet-alert-dialog copied to clipboard

Android studio 3.0 error with sweet-alert-dialog

Open miketrinh1995 opened this issue 7 years ago • 28 comments

On click to show dialog, this error " java.lang.RuntimeException: Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:null" Please help me!

miketrinh1995 avatar Oct 30 '17 07:10 miketrinh1995

Same here

freebumba27 avatar Nov 01 '17 06:11 freebumba27

Same here

fedesenmartin avatar Nov 01 '17 17:11 fedesenmartin

Same here

andreas-cindra avatar Nov 02 '17 03:11 andreas-cindra

Same.. is there a fix ?

neerajmanoharan avatar Nov 02 '17 08:11 neerajmanoharan

i just downgraded build gradle tools version to 'com.android.tools.build:gradle:2.3.3' for example to run my projects , i believe it's not the perfect solution. but it's helpful until this bug fixed with the new build gradle tools

Nobel1893 avatar Nov 02 '17 09:11 Nobel1893

Me too. Please help!

freeskyES avatar Nov 03 '17 01:11 freeskyES

Same issue here.

sarvajeet294 avatar Nov 03 '17 06:11 sarvajeet294

Nobody has the solution for this issue. Anybody know another library like this?

miketrinh1995 avatar Nov 03 '17 08:11 miketrinh1995

There is a solution: you just need to remove it from build.gradle and import it as a module. Then need to delete 3 lines from build.gradle of the library: version, group and apply from... And add it to your app: Project structure -> Modules -> yourmodule-> dependencies

vinczu avatar Nov 03 '17 08:11 vinczu

It still doesn't work for me. Still getting this error: java.lang.RuntimeException: Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:null

rickie avatar Nov 03 '17 14:11 rickie

Are you sure you commented out it from build.gradle? // compile 'cn.pedant.sweetalert:library:1.3'

vinczu avatar Nov 03 '17 14:11 vinczu

I did that, but now I got a new error: Unable to resolve dependency for ':app@appNameDebug/compileClasspath': Could not resolve project :sweetalertdialog.

But now I fixed it by putting this in my build.gradle: compile project(':library')

Since I could not choose 'compile'

Now it works, thank you

rickie avatar Nov 03 '17 14:11 rickie

i solved this error by modify the source code the mothod createAnimationFromXml from Class OptAnimationLoader add } else if (name.equals("YOURPATH.Rotate3dAnimation")) { anim = new Rotate3dAnimation(c, attrs); }

JokerHYC avatar Nov 03 '17 15:11 JokerHYC

@JokerHYC Can you show more details. Step by step. Thank you so much!

miketrinh1995 avatar Nov 04 '17 04:11 miketrinh1995

Same Here

greatjack1 avatar Nov 06 '17 20:11 greatjack1

@JokerHYC what do you mean by "YOURPATH"?

viniciusvieir avatar Nov 07 '17 04:11 viniciusvieir

have any solution?

msingh86 avatar Nov 09 '17 05:11 msingh86

I found the solution. https://jitpack.io/p/Leogiroux/sweet-alert-dialog .

miketrinh1995 avatar Nov 10 '17 03:11 miketrinh1995

same error

msingh86 avatar Nov 10 '17 03:11 msingh86

me too! come on baby...

4what2do avatar Nov 17 '17 07:11 4what2do

Fork from this guy is useful. https://github.com/F0RIS/sweet-alert-dialog

NO above issue. He has also added custom views to SweetAlertDialog.

nitinqtech avatar Nov 22 '17 10:11 nitinqtech

BTW, for those still following this thread:

This is happening because it's failing to turn the 50% string from pivotX / pivotY into the integer '50', which it needs.

It's failing on this line in OptAnimationLoader.java, specifically the call to .newInstance(c, attrs);

anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs);

I forked the repo and changed 50% to 50 and it worked. This is the error I was seeing:

java.lang.RuntimeException: Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:null
    at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:77)                      
    at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:64)
    at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:41)
    at cn.pedant.SweetAlert.OptAnimationLoader.loadAnimation(OptAnimationLoader.java:22)

For the record, this repo is unmaintained, and everyone should switch over to @thomper 's fork at https://github.com/pedant/sweet-alert-dialog/ which works perfectly (thanks @thomper !!).

lucianocheng avatar Dec 21 '17 20:12 lucianocheng

https://github.com/F0RIS/sweet-alert-dialog

this works for me .

chinmayy30 avatar Jan 16 '18 15:01 chinmayy30

https://github.com/F0RIS/sweet-alert-dialog

this worked for me

shashigharti avatar Mar 04 '18 08:03 shashigharti

just change android.enableAapt2=false in gradle.properties but layout stops show previews

DurgeshDilipPawar avatar Apr 07 '18 05:04 DurgeshDilipPawar

i have got the solution no thing to do use same compile 'cn.pedant.sweetalert:library:1.3' and copy the 2 file from library and first

import android.content.Context; import android.content.res.TypedArray; import android.graphics.Camera; import android.graphics.Matrix; import android.util.AttributeSet; import android.util.TypedValue; import android.view.animation.Animation; import android.view.animation.Transformation; import cn.pedant.SweetAlert.sample.R;

public class Rotate3dAnimation extends Animation { private int mPivotXType = ABSOLUTE; private int mPivotYType = ABSOLUTE; private float mPivotXValue = 0.0f; private float mPivotYValue = 0.0f;

private float mFromDegrees;
private float mToDegrees;
private float mPivotX;
private float mPivotY;
private Camera mCamera;
private int mRollType;

public static final int ROLL_BY_X = 0;
public static final int ROLL_BY_Y = 1;
public static final int ROLL_BY_Z = 2;

protected static class Description {
    public int type;
    public float value;
}

Description parseValue(TypedValue value) {
    Description d = new Description();
    if (value == null) {
        d.type = ABSOLUTE;
        d.value = 0;
    } else {
        if (value.type == TypedValue.TYPE_FRACTION) {
            d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) ==
                    TypedValue.COMPLEX_UNIT_FRACTION_PARENT ?
                    RELATIVE_TO_PARENT : RELATIVE_TO_SELF;
            d.value = TypedValue.complexToFloat(value.data);
            return d;
        } else if (value.type == TypedValue.TYPE_FLOAT) {
            d.type = ABSOLUTE;
            d.value = value.getFloat();
            return d;
        } else if (value.type >= TypedValue.TYPE_FIRST_INT &&
                value.type <= TypedValue.TYPE_LAST_INT) {
            d.type = ABSOLUTE;
            d.value = value.data;
            return d;
        }
    }

    d.type = ABSOLUTE;
    d.value = 0.0f;

    return d;
}

public Rotate3dAnimation (Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Rotate3dAnimation);

    mFromDegrees = a.getFloat(R.styleable.Rotate3dAnimation_fromDeg, 0.0f);
    mToDegrees = a.getFloat(R.styleable.Rotate3dAnimation_toDeg, 0.0f);
    mRollType = a.getInt(R.styleable.Rotate3dAnimation_rollType, ROLL_BY_X);
    Description d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotX));
    mPivotXType = d.type;
    mPivotXValue = d.value;

    d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotY));
    mPivotYType = d.type;
    mPivotYValue = d.value;

    a.recycle();

    initializePivotPoint();
}

public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees) {
    mRollType = rollType;
    mFromDegrees = fromDegrees;
    mToDegrees = toDegrees;
    mPivotX = 0.0f;
    mPivotY = 0.0f;
}

public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees, float pivotX, float pivotY) {
    mRollType = rollType;
    mFromDegrees = fromDegrees;
    mToDegrees = toDegrees;

    mPivotXType = ABSOLUTE;
    mPivotYType = ABSOLUTE;
    mPivotXValue = pivotX;
    mPivotYValue = pivotY;
    initializePivotPoint();
}

public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) {
    mRollType = rollType;
    mFromDegrees = fromDegrees;
    mToDegrees = toDegrees;

    mPivotXValue = pivotXValue;
    mPivotXType = pivotXType;
    mPivotYValue = pivotYValue;
    mPivotYType = pivotYType;
    initializePivotPoint();
}

private void initializePivotPoint() {
    if (mPivotXType == ABSOLUTE) {
        mPivotX = mPivotXValue;
    }
    if (mPivotYType == ABSOLUTE) {
        mPivotY = mPivotYValue;
    }
}

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
    mCamera = new Camera();
    mPivotX = resolveSize(mPivotXType, mPivotXValue, width, parentWidth);
    mPivotY = resolveSize(mPivotYType, mPivotYValue, height, parentHeight);
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final Matrix matrix = t.getMatrix();

    mCamera.save();
    switch (mRollType) {
        case ROLL_BY_X:
            mCamera.rotateX(degrees);
            break;
        case ROLL_BY_Y:
            mCamera.rotateY(degrees);
            break;
        case ROLL_BY_Z:
            mCamera.rotateZ(degrees);
            break;
    }
    mCamera.getMatrix(matrix);
    mCamera.restore();

    matrix.preTranslate(-mPivotX, -mPivotY);
    matrix.postTranslate(mPivotX, mPivotY);
}

}

then anim/error_in_frame.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" xmlns:sweet="http://schemas.android.com/apk/res-auto" android:interpolator="@android:anim/linear_interpolator" android:shareInterpolator="true">

<alpha
    android:fromAlpha="0"
    android:toAlpha="1"
    android:duration="400"/>

<sweet: com.packagename.Rotate3dAnimation
    sweet:rollType="x"
    sweet:fromDeg="100"
    sweet:toDeg="0"
    sweet:pivotX="50%"
    sweet:pivotY="50%"
    android:duration="400"/>

imrankhanluhar avatar Oct 04 '18 06:10 imrankhanluhar

For those who are still following the issue: Please find below the link to fixed version of the library.

https://jitpack.io/#AbhisheKundalia/sweet-alert-dialog/v2.0.0

This supports latest android SDK.

AbhisheKundalia avatar Nov 11 '18 19:11 AbhisheKundalia

@AbhisheKundalia you could just do PR but not another one fork, more forks - more confusion for people, which they should use. I update my repo, now it works with Android Studio 3.0 too

F0RIS avatar Dec 03 '18 10:12 F0RIS

java.lang.RuntimeException appears in Android Studio 3.X using Sweet Alert Dialog: Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error: null error

I read a lot of blogs on the Internet and said that using Sweet Alert Dialog has encountered similar problems. The solution is very strange. Some say that it is to download lib and import it into the project.

Some say it is a confusion problem, in fact, the solution is very simple, you can change the added dependency library.

Errored library, comment out

implementation 'cn.pedant.sweetalert:library:1.3'

Add the following library

implementation 'com.github.f0ris.sweetalert:library:1.5.1

Ok run again, problem solving

ashishnimrot avatar Jan 07 '19 16:01 ashishnimrot