frankiesardo / icepick Goto Github PK
View Code? Open in Web Editor NEWAndroid Instance State made easy
License: Eclipse Public License 1.0
Android Instance State made easy
License: Eclipse Public License 1.0
I notice that you use reflection in your code to retrieve the generated methods. It doesn't have to be that way. Performance can be improved IMO by making the generated classes implement an interface
which specifies the API functions in the most generic way possible. That way you can do a simple cast. And this:
Class<?> helper = Class.forName(clsName + Icepick.SUFFIX);
method = helper.getMethod(action.name, cls, getArgumentClass());
becomes:
Class<?> helper = Class.forName(clsName + Icepick.SUFFIX);
ISupport instance = (ISupport) helper;
instance.myInterfaceRestoreFunction(args...)
// Can even put the entire class instance in the cache, instead of just method keys
Icepick for generic field that implements Parcelable generates sth like this
public Bundle restoreInstanceState(Object obj, Bundle state) {
ProductSwitcherActivity target = (ProductSwitcherActivity) obj;
if (state == null) {
return null;
}
Bundle savedInstanceState = state;
target.latestProduct = (T) savedInstanceState.getParcelable(BASE_KEY + "latestProduct");
return parent.restoreInstanceState(target, savedInstanceState);
}
where T is my generic/parcelable. However this cast it not need here. I briefly looked through source code and you might want remove this line: https://github.com/frankiesardo/icepick/blob/master/icepick-processor/src/main/java/icepick/processor/TypecastStrategy.java#L33
There is also an issue with ArrayList
parceling, then class above adds two casts. While it might be needed for non parcel Objects it's not needed when retrieving Parcelable
objects. In other words classes TypecastStrategy
and TypeToBundleMethodMap
probably should be tighter or TypecastStrategy
should know what inspect what element is passsed?
I would suggest, that you generate code like following (example for Long, but should be used for all objects):
Saving:
if (target.icon != null)
outState.putLong(BASE_KEY + "icon", target.icon);
Reading:
if (savedInstanceState.containsKey(BASE_KEY + "icon"))
target.icon = savedInstanceState.getLong(BASE_KEY + "icon");
Otherwise, you library which is really very useful, can't be used with null values...
Having difficulty saving and restoring state of a data object, which has JodaTime#DateTime fields in it.
Stack trace:
http://pastebin.com/mdpQVWFM
Caused by: icepick.Icepick$UnableToSerializeException: java.lang.RuntimeException: Failed to invoke public org.joda.time.Chronology() with no args
at icepick.Icepick.unwrap(Icepick.java:55)
...
GalleryItem is the offending object, and PostFragment is where I'm trying to save and restore.
While i was implementing Icepick, i copy-pasted a bit too fast and almost tried to save a view in the saved state bundle. So i thought it'd be a cool idea if Icepick would throw a warning that you are trying to save certain types of context related classes in the bundle.
The easiest way i could think of, is just to have a blacklist of such classes. Anything that extends a View, Activity, Fragment, Application, Context, and so on. I don't know the inner workings of annotation processing, but one could maybe also check if the object being saved has a field of the type Context. So even custom classes would trigger a warning.
This seems like a great library because I hate the 'save/load instance state' boilerplate code.
I have found however that it does not work in combination with AndroidAnnotations. When I decorate an Activity with @EActivity attribute (and reference it using the underscore name in the manifest, eg "MainActivity_") then any fields decorated with @icicle are no longer saved automatically.
Most likely the issue is that AndroidAnnotations generates the new class with the underscore name and icepick is not compatible with this?
Is there anything I can do to solve this?
like butterknife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
not found :(
had to hunt maven central to get the latest version number, would be nice if it was in the readme!
Hi, I am using proguard and faced with problem. Current Icepick proguard rules described here prevent from obfuscate class names.
I found similar issue for butterKnife and took solution from there.
JakeWharton/butterknife#117
Here is correct proguard rules:
-dontwarn icepick.**
-keep class **$$Icicle { *; }
-keepclasseswithmembernames class * {
@icepick.* <fields>;
}
Is it possible to host the Icepick at the Maven Central instead (or as well as) of Clojars?
Now about outomatically calling Parcels.wrap/unwrap for objects that are annotated with @parcel?
Not a big deal, but I find this text annoying building. Maybe only have it in debug version of the library? If you don't agree, again NBD, just a though.
Also, thanks for building this and your blog post about building it. It inspired me to make my own Annotation Processor.
There is a typo on line 70 in https://github.com/frankiesardo/icepick/blob/master/icepick/src/icepick/Injector.java
Byte arrays are not possible to restore.
Is there planned support for classes written in Kotlin? Currently members in a Kotlin class annotated with "Icicle" do not get saved.
I have a custom LinearLayout
like this with Mail extends Parcelable
:
public class LabelLayout extends LinearLayout {
@Icicle Mail mail;
}
public class LabelLayout$$Icicle<T extends LabelLayout> extends View<T> {
private final static Helper H = new Helper("com.hannesdorfmann.mosby.sample.mail.label.LabelLayout$$Icicle.");
public Parcelable restore(T target, Parcelable p) {
Bundle state = (Bundle) p;
target.mail = H.getParcelable(state, "mail");
return super.restore(target, H.getParent(state));
}
public Parcelable save(T target, Parcelable p) {
Bundle state = H.putParent(super.save(target, p));
H.putParcelable(state, "mail", target.mail);
return state;
}
}
Everything works like expected. However, if I turn "destroy activity" in the developer options on i get the following exception:
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@322c9bd9: Unmarshalling unknown type code 67 at offset 432
at android.os.Parcel.readValue(Parcel.java:2222)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:804)
at icepick.Injector$Helper.getParcelable(Injector.java:294)
at com.hannesdorfmann.mosby.sample.mail.label.LabelLayout$$Icicle.restore(LabelLayout$$Icicle.java:14)
at com.hannesdorfmann.mosby.sample.mail.label.LabelLayout$$Icicle.restore(LabelLayout$$Icicle.java:8)
at icepick.Icepick.restoreInstanceState(Icepick.java:81)
at com.hannesdorfmann.mosby.sample.mail.label.LabelLayout.onRestoreInstanceState(LabelLayout.java:169)
at android.view.View.dispatchRestoreInstanceState(View.java:13621)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2893)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2893)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2893)
at android.view.View.restoreHierarchyState(View.java:13599)
at android.support.v4.app.Fragment.restoreViewState(Fragment.java:465)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:979)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1118)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1927)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:544)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
at android.app.Activity.performStart(Activity.java:5949)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
ย ย ย ย ย ย ย ย ย ย ย ย at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
ย ย ย ย ย ย ย ย ย ย ย ย at android.app.ActivityThread.access$800(ActivityThread.java:144)
ย ย ย ย ย ย ย ย ย ย ย ย at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
ย ย ย ย ย ย ย ย ย ย ย ย at android.os.Handler.dispatchMessage(Handler.java:102)
ย ย ย ย ย ย ย ย ย ย ย ย at android.os.Looper.loop(Looper.java:135)
ย ย ย ย ย ย ย ย ย ย ย ย at android.app.ActivityThread.main(ActivityThread.java:5221)
ย ย ย ย ย ย ย ย ย ย ย ย at java.lang.reflect.Method.invoke(Native Method)
ย ย ย ย ย ย ย ย ย ย ย ย at java.lang.reflect.Method.invoke(Method.java:372)
ย ย ย ย ย ย ย ย ย ย ย ย at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
ย ย ย ย ย ย ย ย ย ย ย ย at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
I'm not sure what the problem is, but as far as I see you using a bundle. However, Bundle
is not persistent, while PersistableBundle
is. I'm not sure if that solve the problem, just a hint where the problem may comes from.
-keepnames class * { @icepick.State *; }
prevents proguard to execute
-repackageclasses 'k'
If I remove the keepnames line obfuscation runs as expected. And strangely it does not seem to affect the app.
Could you suggest why this is happening and if I really need this line in the proguard rules ?
If I have a classes
public abstract class PetActivity extends Activity {
@Icicle mName;
}
public abstract class CatActivity extends PetActivity {
@Icicle mNumClaws;
}
The code generator does write not persistence code for nName for CatActivity.
Hope that makes sense, I tried to clone and submit a pull request but this looks like a bit more jiggery pokery than I expected.
EDIT: I looked through the source and it does seem you are processing the super type hierarchy so unsure if I am doing something wrong here.
Thanks for the library!
I was trying to icicle-ize a List<MyModel>
, with MyModel
implementing Parcelable
. I'm not sure I read it correctly, but #7 and #21 suggest that some related behavior was removed.
The processor fails with Don't know how to put a java.util.List<com.example.MyModel> inside a Bundle
. When trying to use an ArrayList<MyModel>
instead, the processor generates code that doesn't compile (can't cast a List<SuperType>
to List<SubType>
):
target.myModels = (java.util.ArrayList<com.example.MyModel>) savedInstanceState.getParcelableArrayList(BASE_KEY + "myModels");
using an ArrayList<Parcelable>
or a MyModel[]
works, but requires a lot of manual wrapping/unwrapping.
Would automatically converting a list like that into an ArrayList<Parcelable>
or a Parcelable[]
not be an option?
I keep getting
Not found. Trying superclass android.support.v7.app.ActionBarActivity
MISS: Reached framework class. Abandoning search.
any idea what could be going on? I have pretty much the same code as the example
Hi Frankie,
I hope you are fine. We already met in DroidCon London I believe. I remember that your clean code impressed me, and it's still the case with IcePick. Good stuff.
I have been thinking for a long time about a project on Android to remove the boiler plate from many libs. I think this might interest you :
https://github.com/stephanenicolas/loglifecycle
The interest doesn't lie in the lib itself but on the technology it dwells on. I believe it could be relatively easy to setup such a thing to remove all boiler plate from IcePick.
Interested ?
Cheers,
Stรฉphane
It would be nice if we could link
our Javadoc to Icepick's. I believe you can just create a gh-pages
branch, drop the apidocs
folder in there, and then it will be available at https://frankiesardo.github.io/icepick/apidocs/
Here's an example:
https://github.com/pushbit/sprockets/tree/gh-pages/java/apidocs
https://pushbit.github.io/sprockets/java/apidocs/
Hi, Great library thanks, when using @icicle on a parcelable I noticed the generated code does not set the correct class loader on the bundle which can lead to badparcelableexception when marshalling, ie:-
Generated code is as follows:
target.mBasketRecord = (com.justeat.app.data.BasketsRecord) savedInstanceState.getParcelable(BASE_KEY + "mBasketRecord");
Where it should be something like this:
savedInstanceState.setClassloader(com.justeat.app.data.BasketsRecord.class.getClassLoader());
target.mBasketRecord = (com.justeat.app.data.BasketsRecord) savedInstanceState.getParcelable(BASE_KEY + "mBasketRecord");
Hope that makes sense.
Ignore, can't delete.
I get this when I run the project
Dependecies:
compile 'frankiesardo:icepick:3.0.2'
provided 'frankiesardo:icepick-processor:3.0.2'
My proguard:
-dontobfuscate
# okhttp
-dontwarn com.squareup.okhttp.internal.**
# butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
# Joda
-dontwarn org.joda.convert.**
-dontwarn org.joda.time.tz.DateTimeZoneBuilder$PrecalculatedZone
# EventBus
-keepclassmembers class ** { public void onEvent*(**); }
# Only required if you use AsyncExecutor
-keepclassmembers class * extends de.greenrobot.event.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
# Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.integration.okhttp.OkHttpGlideModule
# AppCompat
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
# superrecyclerview
-dontwarn com.malinskiy.superrecyclerview.SwipeDismissRecyclerViewTouchListener*
# leakcanary
-keep class org.eclipse.mat.** { *; }
-keep class com.squareup.leakcanary.** { *; }
# Craslytics https://dev.twitter.com/crashlytics/android/proguard-dexguard
-keepattributes SourceFile,LineNumberTable
# Icepick
#-dontwarn icepick.processor.**
#-keep class **$$Icicle { *; }
#-keepnames class * { @icepick.Icicle *; }
-dontwarn icepick.**
-keep class **$$Icicle { *; }
-keepnames class * { @icepick.Icicle *;}
-keepclasseswithmembernames class * { @icepick.* <fields>; }
Error:
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning:library class com.google.auto.common.MoreTypes$1 extends or implements program class com.google.common.base.Equivalence
Warning:there were 1 instances of library classes depending on program classes.
You must avoid such dependencies, since the program classes will
be processed, while the library classes will remain unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
:app:proguardDebug FAILED
Error:Execution failed for task ':app:proguardDebug'.
> java.io.IOException: Please correct the above warnings first.
library i get a 404 error
This library use serialize or parcelable or ... for store data?
Information:Gradle tasks [:AbcApp:assembleDebug]
:AbcApp:preBuild UP-TO-DATE
:AbcApp:preDebugBuild UP-TO-DATE
:AbcApp:checkDebugManifest
:AbcApp:preReleaseBuild UP-TO-DATE
:android-support-v7-appcompat:compileLint
:android-support-v7-appcompat:copyReleaseLint UP-TO-DATE
:android-support-v7-appcompat:mergeReleaseProguardFiles UP-TO-DATE
:android-support-v7-appcompat:preBuild UP-TO-DATE
:android-support-v7-appcompat:preReleaseBuild UP-TO-DATE
:android-support-v7-appcompat:checkReleaseManifest
:android-support-v7-appcompat:prepareReleaseDependencies
:android-support-v7-appcompat:compileReleaseAidl UP-TO-DATE
:android-support-v7-appcompat:compileReleaseRenderscript UP-TO-DATE
:android-support-v7-appcompat:generateReleaseBuildConfig UP-TO-DATE
:android-support-v7-appcompat:generateReleaseAssets UP-TO-DATE
:android-support-v7-appcompat:mergeReleaseAssets UP-TO-DATE
:android-support-v7-appcompat:generateReleaseResValues UP-TO-DATE
:android-support-v7-appcompat:generateReleaseResources UP-TO-DATE
:android-support-v7-appcompat:packageReleaseResources UP-TO-DATE
:android-support-v7-appcompat:processReleaseManifest UP-TO-DATE
:android-support-v7-appcompat:processReleaseResources UP-TO-DATE
:android-support-v7-appcompat:generateReleaseSources UP-TO-DATE
:android-support-v7-appcompat:processReleaseJavaRes UP-TO-DATE
:android-support-v7-appcompat:compileReleaseJava UP-TO-DATE
:android-support-v7-appcompat:packageReleaseJar UP-TO-DATE
:android-support-v7-appcompat:compileReleaseNdk UP-TO-DATE
:android-support-v7-appcompat:packageReleaseJniLibs UP-TO-DATE
:android-support-v7-appcompat:packageReleaseLocalJar UP-TO-DATE
:android-support-v7-appcompat:packageReleaseRenderscript UP-TO-DATE
:android-support-v7-appcompat:bundleRelease UP-TO-DATE
:robodemolib:compileLint
:robodemolib:copyReleaseLint UP-TO-DATE
:robodemolib:mergeReleaseProguardFiles UP-TO-DATE
:robodemolib:preBuild UP-TO-DATE
:robodemolib:preReleaseBuild UP-TO-DATE
:robodemolib:checkReleaseManifest
:robodemolib:prepareReleaseDependencies
:robodemolib:compileReleaseAidl UP-TO-DATE
:robodemolib:compileReleaseRenderscript UP-TO-DATE
:robodemolib:generateReleaseBuildConfig UP-TO-DATE
:robodemolib:generateReleaseAssets UP-TO-DATE
:robodemolib:mergeReleaseAssets UP-TO-DATE
:robodemolib:generateReleaseResValues UP-TO-DATE
:robodemolib:generateReleaseResources UP-TO-DATE
:robodemolib:packageReleaseResources UP-TO-DATE
:robodemolib:processReleaseManifest UP-TO-DATE
:robodemolib:processReleaseResources UP-TO-DATE
:robodemolib:generateReleaseSources UP-TO-DATE
:robodemolib:processReleaseJavaRes UP-TO-DATE
:robodemolib:compileReleaseJava UP-TO-DATE
:robodemolib:packageReleaseJar UP-TO-DATE
:robodemolib:compileReleaseNdk UP-TO-DATE
:robodemolib:packageReleaseJniLibs UP-TO-DATE
:robodemolib:packageReleaseLocalJar UP-TO-DATE
:robodemolib:packageReleaseRenderscript UP-TO-DATE
:robodemolib:bundleRelease UP-TO-DATE
:AbcApp:prepareCD64AndroidSupportV7AppcompatUnspecifiedLibrary UP-TO-DATE
:AbcApp:prepareCD64RobodemolibUnspecifiedLibrary UP-TO-DATE
:AbcApp:prepareComAndroidSupportCardviewV72103Library UP-TO-DATE
:AbcApp:prepareComAndroidSupportRecyclerviewV72103Library UP-TO-DATE
:AbcApp:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:AbcApp:prepareComFacebookAndroidFacebookAndroidSdk410Library UP-TO-DATE
:AbcApp:prepareComFacebookFrescoDrawee061Library UP-TO-DATE
:AbcApp:prepareComFacebookFrescoFbcore061Library UP-TO-DATE
:AbcApp:prepareComFacebookFrescoFresco061Library UP-TO-DATE
:AbcApp:prepareComFacebookFrescoImagepipeline061Library UP-TO-DATE
:AbcApp:prepareComGoogleAndroidGmsPlayServicesAds750Library UP-TO-DATE
:AbcApp:prepareComGoogleAndroidGmsPlayServicesAnalytics750Library UP-TO-DATE
:AbcApp:prepareComGoogleAndroidGmsPlayServicesAppindexing750Library UP-TO-DATE
:AbcApp:prepareComGoogleAndroidGmsPlayServicesBase750Library UP-TO-DATE
:AbcApp:prepareComGoogleAndroidGmsPlayServicesLocation750Library UP-TO-DATE
:AbcApp:prepareComGoogleAndroidGmsPlayServicesMaps750Library UP-TO-DATE
:AbcApp:prepareDebugDependencies
:AbcApp:compileDebugAidl UP-TO-DATE
:AbcApp:compileDebugRenderscript UP-TO-DATE
:AbcApp:generateDebugBuildConfig UP-TO-DATE
:AbcApp:generateDebugAssets UP-TO-DATE
:AbcApp:mergeDebugAssets UP-TO-DATE
:AbcApp:generateDebugResValues UP-TO-DATE
:AbcApp:generateDebugResources UP-TO-DATE
:AbcApp:mergeDebugResources UP-TO-DATE
:AbcApp:processDebugManifest UP-TO-DATE
:AbcApp:processDebugResources UP-TO-DATE
:AbcApp:generateDebugSources UP-TO-DATE
:AbcApp:processDebugJavaRes UP-TO-DATE
:AbcApp:compileDebugJava UP-TO-DATE
:AbcApp:compileDebugNdk UP-TO-DATE
:AbcApp:compileDebugSources UP-TO-DATE
:AbcApp:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/nineoldandroids/animation/Animator$AnimatorListener;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:732)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
1 error; aborting
Error:Execution failed for task ':AbcApp:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
icepick/icepick/src/icepick/Injector.java
Line 358 in 614c495
and
icepick/icepick/src/icepick/Injector.java
Line 363 in 614c495
Hello,
Thanks for this great lib.
I am having this issue with int type:
inconvertible types
found : java.io.Serializable
required: int
The workaround is to use Integer.
The library do not support primitive types ?
Thanks
We enabled code obfuscation for our project and had issues with provided proguard config. We had to add -keepnames class * { @icepick.State *;}
to properly run our app.
-dontwarn icepick.**
-keep class **$$Icepick { *; }
-keepnames class * { @icepick.State *;}
-keepclasseswithmembernames class * {
@icepick.* <fields>;
}
My colleague make a mistake , he use icepick
like this:
@Icicle
ArrayList<File> ...
When i run the app,it has a nullPointExceptoin
, at that time, i don't know he used it like that, some i check code,but i only find a error at Error window
like this:
icepick.annotation.IcicleField$UnableToSerializeException: Don't know how to put a java.util.List<java.io.File> into a Bundle
at icepick.annotation.IcicleField$Factory.convert(IcicleField.java:44)
at icepick.annotation.IcicleField$Factory.from(IcicleField.java:32)
at icepick.annotation.IcicleFactory.makeField(IcicleFactory.java:34)
at icepick.annotation.IcicleProcessorState.convert(IcicleProcessorState.java:87)
at icepick.annotation.IcicleProcessorState.convert(IcicleProcessorState.java:79)
at icepick.annotation.IcicleProcessorState.process(IcicleProcessorState.java:27)
at icepick.annotation.IcicleProcessor.process(IcicleProcessor.java:20)
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139)
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121)
at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)
at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:134)
at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:813)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:432)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:364)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:178)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:301)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:60)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:184)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
I remember i don't use ``icepick` like this, i don't know where the error happened.So i spend about one hour check my code .
We need to show error logs use another way?
Hi,
I get an error when I try to run my application.
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:library:compileLint
:library:copyReleaseLint UP-TO-DATE
:library:preBuild UP-TO-DATE
:library:preReleaseBuild UP-TO-DATE
:library:checkReleaseManifest
:library:preDebugAndroidTestBuild UP-TO-DATE
:library:preDebugBuild UP-TO-DATE
:library:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:library:prepareReleaseDependencies
:library:compileReleaseAidl UP-TO-DATE
:library:compileReleaseRenderscript UP-TO-DATE
:library:generateReleaseBuildConfig UP-TO-DATE
:library:generateReleaseAssets UP-TO-DATE
:library:mergeReleaseAssets UP-TO-DATE
:library:generateReleaseResValues UP-TO-DATE
:library:generateReleaseResources UP-TO-DATE
:library:mergeReleaseResources UP-TO-DATE
:library:processReleaseManifest UP-TO-DATE
:library:processReleaseResources UP-TO-DATE
:library:generateReleaseSources UP-TO-DATE
:library:compileReleaseJava UP-TO-DATE
:library:extractReleaseAnnotations UP-TO-DATE
:library:mergeReleaseProguardFiles UP-TO-DATE
:library:processReleaseJavaRes UP-TO-DATE
:library:packageReleaseJar UP-TO-DATE
:library:compileReleaseNdk UP-TO-DATE
:library:packageReleaseJniLibs UP-TO-DATE
:library:packageReleaseLocalJar UP-TO-DATE
:library:packageReleaseRenderscript UP-TO-DATE
:library:packageReleaseResources UP-TO-DATE
:library:bundleRelease UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:app:prepareComAndroidSupportPaletteV72200Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72200Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:app:prepareComDaimajiaAndroidanimationsLibrary113Library UP-TO-DATE
:app:prepareComDaimajiaEasingLibrary100Library UP-TO-DATE
:app:prepareComMcxiaokeViewpagerindicatorLibrary241Library UP-TO-DATE
:app:prepareComNispokSnackbar2106Library UP-TO-DATE
:app:prepareGinsonlineLibraryUnspecifiedLibrary UP-TO-DATE
:app:prepareJpWasabeefRecyclerviewAnimators113Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.util.ExceptionWithContext: no mapping specified for register
at com.android.dex.util.ExceptionWithContext.withContext(ExceptionWithContext.java:45)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:369)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
at com.android.dx.command.dexer.Main.processClass(Main.java:729)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.RuntimeException: no mapping specified for register
at com.android.dx.ssa.BasicRegisterMapper.map(BasicRegisterMapper.java:63)
at com.android.dx.ssa.SsaInsn.mapRegisters(SsaInsn.java:159)
at com.android.dx.ssa.SsaMethod.mapRegisters(SsaMethod.java:394)
at com.android.dx.ssa.back.SsaToRop.moveParametersToHighRegisters(SsaToRop.java:235)
at com.android.dx.ssa.back.SsaToRop.convert(SsaToRop.java:118)
at com.android.dx.ssa.back.SsaToRop.convertToRopMethod(SsaToRop.java:69)
at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:101)
at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:72)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:297)
... 15 more
...while processing invoke (Ljava/lang/Object;)Ljava/lang/Object;
...while processing stencil/ast$fn__389.class
1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
project build.gradle file: http://pastebin.com/rVZj2bwA
module build.gradle file: http://pastebin.com/3aXNH5WT
I also updated my JDK (from 1.7.0_60 to 1.8.0_40), but I'm still getting the same error..
Any idea how I can fix this?
Is it possible for the processor to the create an instance of class that implements IcicleClass and use reflection to call it's save()
and restore()
methods, passing a bundle. I apologize for writing up a use case instead of some proof of concept code. I have no idea where to start with annotation processing.
class ViewState implements IcicleClass {
@Icicle boolean isRefreshing;
@Icicle boolean emtyLayoutShowing;
@Override
public void save(Bundle savedInstanceState) {
Icepick.saveInstanceState(this, savedInstanceState);
}
@Override
public void restore(Bundle savedInstanceState) {
Icepick.restoreInstanceState(this, savedInstanceState);
}
}
class MyFragment extends Fragment {
@IcicleClass
ViewState mViewState;
@Icicle
ArrayList<Parcelable> mData;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Icepick.restoreInstanceState(this, savedInstanceState);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}
}
Or would it just be easier to make ViewState implement Parcelable. Just an idea.
$$icepick class isn't generated if we use icepick and android apt plugin.
Solution that I found is to change the dependency scope from provided
to apt
.
From:
compile 'frankiesardo:icepick:3.0.2'
provided 'frankiesardo:icepick-processor:3.0.2'
To:
compile 'frankiesardo:icepick:3.0.2'
apt 'frankiesardo:icepick-processor:3.0.2'
Hi Frankie,
very very nice lib idea. I have been thinking to that problem quite often and didn't push enough. You did great.
Would it be possible to get a better name for the ICicle annotation ? Something like @Icepick. It would make the code cleaner and the lib more recognizable.
Hope to see that at DroidCon London Barcamp this year ;)
S.
Hi Frankie,
Since I heard of "icepick" I wanted to add it, to my project. But, for some reason it's not working for me. Also I don't know where to ask for this, sorry if this is not the good place. I hope that you can help me.
I'm trying to save two properties in my activity
@icicle String title;
@icicle int position;
And my BaseActivity Iooks like this
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Icepick.restoreInstanceState(this, savedInstanceState);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}
But, when I rotate the device, the properties title and position are always null and ZERO
I added the library with gradle and also I pasted your suggestion for the proguard file. What I'm missing?
How can be sure if IcePick is saving the properties? Thanks
Would it be possible to have a more descriptive exception on null objects or any exception detailing one of the objects being injected?
Currently i have an Activity with a large number of @icicles, and it's hard to find out which one is wrong once users report this error through Google Play.
java.lang.NullPointerException
at com.Activity$$Icicle.saveInstanceState(Activity$$Icicle.java:27)
at com.Activity$$Icicle.saveInstanceState(Activity$$Icicle.java:6)
at icepick.Action$1.invoke(Action.java:6)
at icepick.ObjectInjector.inject(ObjectInjector.java:16)
at icepick.Icepick.saveInstanceState(Icepick.java:17)
at
Does Icepick work with Fragments?
Or is it an activity/view only thing?
Could you please explain the setup with eclipse?
No matter what combination I try (putting a lib to "Annotation Processing"/"Factory Path" and adding a lib to android project), I eiteher get a java.lang.NoClassDefFoundError or after the preprocessing, I have no extra output in the .apt_generatad files...
I though, I should add the precessor lib to "Annotation Processing"/"Factory Path" and the other library to my android project, but that does not work...
I use POJOs with Jackson annotations and Parceler for my client model. Such a class looks like this:
@Parcel
public class Properties {
@JsonProperty("product")
private String product;
@JsonProperty("product")
public String getProduct() {
return product;
}
@JsonProperty("product")
public void setProduct(String product) {
this.product = product;
}
}
When I let Icepick handle the instance state the following error occurs:
Parceler: Reflection is required to modify private field: String product, consider using non-private.
Do you know why this is happening?
javax.annotation.processing.FilerException: Source file already created: /zszydr/.apt_generated/ ...$$Icicle.java Impossible to create ...$$Icicle
Shouldn't this go in gitignore? Can create a PR if you want.
Is it hard to create an Icepick variant that will put data into a map instead of Bundle? I'd like to use Icepick for parts of an application that do not have access to Android SDK.
I'm talking about MVP architecture, where Presenter is SDK-independent, so presenter's state could be saved into a Map and serialized by SDK-dependent code later.
This would allow to easily create code that can be tested without SDK/robolectric or used with https://github.com/google/j2objc.
Is there a way to exclude an activity (Settings, in my case) from being instantiated again? Upon a theme change, I use getActivity().recreate to swap themes, but then I have two instances of Settings activity and must hit the back button twice to remove them. This does not happen when I disable Icepick.
It would be a very nice addition to be able to place the @icicle annotation on basic views like EditText, Spinner, ... and their state would be saved / restored to/from the bundle.
is it possible to add support for default values?
java.lang.NoClassDefFoundError: com/squareup/java/JavaWriter
at com.github.frankiesardo.icepick.annotation.IcicleProcessor.writeHelpers(IcicleProcessor.java:65)
at com.github.frankiesardo.icepick.annotation.IcicleProcessor.process(IcicleProcessor.java:32)
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139)
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121)
at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)
at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:134)
at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:813)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:432)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:364)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:178)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:301)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:60)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:178)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:513)
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:422)
at org.eclipse.jdt.internal.ui.util.CoreUtility$BuildJob.run(CoreUtility.java:162)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
thx
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.