Can you try building a test extension with AI2 sources or extension-template implementing that class and see if you get the same error? Make sure that when you build the extension, you build it using ant extensions -Dproguard=1
.
package AnimationHelper;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.util.Log;
import android.view.View;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
@DesignerComponent(
category = ComponentCategory.EXTENSION,
nonVisible = true,
version = 1
)
@SimpleObject(external = true)
public class AnimationHelper extends AndroidNonvisibleComponent {
public AnimationHelper(ComponentContainer container) {
super(container.$form());
}
@SimpleFunction()
public void Scale(final AndroidViewComponent component, final float startValue, final float endValue, final long duration) {
final View view = component.getView();
ValueAnimator animator = ValueAnimator.ofFloat(startValue, endValue);
animator.setDuration(duration);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
view.setScaleX((Float) valueAnimator.getAnimatedValue());
view.setScaleY((Float) valueAnimator.getAnimatedValue());
view.requestLayout();
view.postInvalidate();
}
});
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
view.setVisibility(View.VISIBLE);
Log.v("AnimationHelper", "onAnimationStart");
}
@Override
public void onAnimationEnd(Animator animator) {
Log.v("AnimationHelper", "onAnimationEnd");
view.setScaleX(endValue);
view.setScaleY(endValue);
}
@Override
public void onAnimationCancel(Animator animator) {
Log.v("AnimationHelper", "onAnimationCancel");
}
@Override
public void onAnimationRepeat(Animator animator) {
Log.v("AnimationHelper", "onAnimationRepeat");
}
});
animator.start();
}
}
private void showToast(final String msg) {
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
}
@SimpleFunction
public void ListenToActivityChanges() {
Application application = (Application) context.getApplicationContext();
application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) {
showToast("onActivityCreated" + activity.getClass().getSimpleName());
}
public void onActivityStarted(@NonNull Activity activity) {
showToast("onActivityStarted" + activity.getClass().getSimpleName());
}
public void onActivityResumed(@NonNull Activity activity) {
showToast("onActivityResumed" + activity.getClass().getSimpleName());
}
public void onActivityPaused(@NonNull Activity activity) {
showToast("onActivityPaused" + activity.getClass().getSimpleName());
}
public void onActivityStopped(@NonNull Activity activity) {
showToast("onActivityStopped" + activity.getClass().getSimpleName());
}
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
showToast("onActivitySaveInstanceState" + activity.getClass().getSimpleName());
}
public void onActivityDestroyed(@NonNull Activity activity) {
showToast("onActivityDestroyed" + activity.getClass().getSimpleName());
}
});
}
Everything seems to work. Tested in companion as well. No compilation issues.
The error is coming from Firestore library :
package com.google.firebase.firestore.remote;
public final class AndroidConnectivityMonitor implements ConnectivityMonitor {
// ...
private void configureBackgroundStateListener() {
Application application = (Application)this.context.getApplicationContext();
final AtomicBoolean inBackground = new AtomicBoolean();
application.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) {
if (inBackground.compareAndSet(true, false)) {
AndroidConnectivityMonitor.this.raiseForegroundNotification();
}
}
public void onActivityStarted(@NonNull Activity activity) {
if (inBackground.compareAndSet(true, false)) {
AndroidConnectivityMonitor.this.raiseForegroundNotification();
}
}
public void onActivityResumed(@NonNull Activity activity) {
if (inBackground.compareAndSet(true, false)) {
AndroidConnectivityMonitor.this.raiseForegroundNotification();
}
}
public void onActivityPaused(@NonNull Activity activity) {
}
public void onActivityStopped(@NonNull Activity activity) {
}
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
}
public void onActivityDestroyed(@NonNull Activity activity) {
}
});
application.registerComponentCallbacks(new ComponentCallbacks2() {
public void onTrimMemory(int level) {
if (level == 20) {
inBackground.set(true);
}
}
public void onConfigurationChanged(@NonNull Configuration newConfig) {
}
public void onLowMemory() {
}
});
}
}
I was able to build it successfully with Rush when I disabled desugaring.
# rush.yml
build:
desugar:
enable: false
desugar_deps: false
You should not enable it if your extension (or its dependencies) doesn’t use any Java 8 language features.
And that error is?
If i disable desugaring, then the app doesn’t compile. As for the error i was saying that the error comes because of the firestore library that I am using.
Then you’d have to turn off the optimization of the extension. It seems like the desugar tool is modifying the bytecode in a way ProGuard doesn’t know how to work with.
I will try.
Hi @Shreyash i have a suggestion so if a users uses a aar can you add a feature that it automatically extracts classes.jar from it and uses that jar instead?
Thank you,
Aarush Kumar.
It would be a nice little abstraction to have, but I think it’d lead to confusion among users. If Rush allowed the use of AARs, one might expect they can utilize everything an AAR has to offer (XML resources, manifest elements, etc.) in their extensions, which simply isn’t possible yet with AI2.
then probably you can add that user can enable from rush.yml
and add a comment there about what it does in detail
as for the aar file support, I would suggest to support classes.jar, progaurd and android manifest files.
Hey @shreyash I guess this has something to do with the error I mentioned above :
android.app.Application.ActivityLifecycleCallbacks
Source : d8 | Android Developers
I encounter these errors when the interface is used but its default methods are not implemened.
One more question: Do you provide android.jar
file when using d8 as it is a compiled code that our extension depends upon?
I found a related issue on stackoverflow but it pretty old:
No, it has nothing to do with that error. The error you’re getting is during optimization (ProGuard) step which happens before d8 is invoked during the dexing step. Moreover, Rush uses the desugar
tool used in Bazel and doesn’t actually rely upon d8 for desugaring of Java 8 language features.
Yes.
Thanks for linking that. I think I now have a clear vision of what might have possibly gone wrong.
│ erro Kotlin files detected. Please enable Kotlin in rush.yml.
└ failed
How ?
hi @Nami_Chand looks like you have kotlin files did you choose kotlin while creating project if not then please enable in rush.yml
I am using java and kotlin in one extension.
How can i enable in yml.
add -
kotlin:
enable: true
under build:
┌ Checking project files
│ info Checking metadata file (rush.yml)
│
│ erro The following error occurred while validating metadata file (rush.yml):
│ Bad state: Too many elements
└ failed
• Build failed [63ms] [1 error]
I am encountering this issue while building … where i havent changed anything in .yml file @Shreyash