android - Icepick 坏了吗?

标签 android android-gradle-plugin android-library

我用一个 fragment 尝试了一些非常简单的测试。但是 Icepick 似乎并没有在 outState 包中保存 String test 的值......

public class MyFragment extends Fragment {
    @Icicle String test;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Icepick.restoreInstanceState(this,savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_settings, container, false);
        Log.d(TAG,"restored value of test="+test);
        return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        test="I have a value";
        super.onSaveInstanceState(outState);
        Icepick.saveInstanceState(this,outState);
        Log.d(TAG, "test="+test);
   }

我的 gradle 构建看起来像这样:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.my31daychallenge.mysleepchallenge"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.jakewharton.threetenabp:threetenabp:1.0.1'
    apt 'com.bluelinelabs:logansquare-compiler:1.1.0'
    compile 'com.bluelinelabs:logansquare:1.1.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'frankiesardo:icepick:3.0.0'
    provided 'frankiesardo:icepick-processor:3.0.0'
}

请注意,我尝试了最新版本的 Icepick 3.0.2 和 3.0.3-SNAPSHOT,但都没有用,所以我想使用更早的版本得到相同的结果。

还有:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {url "https://clojars.org/repo/"}
    }
}

我错过了什么?

最佳答案

在您的 build.gradle 文件中,对于这一行 provided 'frankiesardo:icepick-processor:3.0.0'provided 更改为 apt .这应该可以解决问题。

来源:https://github.com/frankiesardo/icepick/issues/56

关于android - Icepick 坏了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31514150/

相关文章:

android - Gradle:添加依赖项的优点/缺点

java - com.kami2017.app.MainActivity.onCreate上的Android Studio错误

java - 如何解决 NativeScript Skidekick 中与模拟器 java 相关的错误

java - 应用程序发布 APK 上的依赖项冲突,但调试时不冲突?

java - 适用于 Android 的 MailCore 替代品

android - Android 库中的线程安全

android - 如何导出 AAR 库及其文档?

android - 在 scrollView android 上实现缩放

android - 找不到错误 : cannot access zzbfm class file for com. google.android.gms.internal.zzbfm

android - 如何在 Android Studio 中构建 AOSP 项目