parceler icon indicating copy to clipboard operation
parceler copied to clipboard

Problem with Android Studio 3.0 Beta 4

Open carmas123 opened this issue 8 years ago • 24 comments

I've a big probject and use Parceler with success, thank you. I've a problem when I try to make project in debug: If I edit my code and run debug when I use Parceler I got an exception with Class not found. If I recompile this probject the problem has gone and all work fine. Can anyone help me please (to recompile the project every time it take 2min :( )

This is the exception:

Caused by: org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for com.example.data.model.MyClass, verify that your class is configured properly and that the Parcelable class com.example.data.model.MyClass$$Parcelable is generated by Parceler.

carmas123 avatar Sep 03 '17 16:09 carmas123

Can you share MyClass?

johncarl81 avatar Sep 04 '17 04:09 johncarl81

My Class is a simple class model used with DBFlow:

@Parcel
@Table(database = DBLocal::class)
class MyClass : AbstractModel() {
    @Column(length = 3)
    @PrimaryKey

    var codice: String = ""

    @Column(length = 30)
    var descrizione: String = ""

    @Column
    var percentuale: Float = 0F

    @Column
    var noImponibile: Int = 0
}

The exception was raised into:

        public ParcelableFactory findClass(Class clazz){
            try {
                Class parcelWrapperClass = Class.forName(buildParcelableImplName(clazz));  <--HERE
                return new ParcelableFactoryReflectionProxy(clazz, parcelWrapperClass);
            } catch (ClassNotFoundException e) {
                return null;
            }
        }

Class.forName("com.example.MyClass$$Parcelable") <-- this cause the exception

I suppose that the problem is Gradle and Kapt, I use Kotlin and my gradle config is this: implementation "org.parceler:parceler-api:1.1.9" kapt "org.parceler:parceler:1.1.9"

carmas123 avatar Sep 04 '17 07:09 carmas123

I found the problem:

The problem appaer when mixing into gradle "annotationProcessor" and "kapt" if any library need annotationProcessor and use kotlin to solve the problem is need to add:

android {
...
  defaultConfig {
   ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
  }
}

this solve the problem.

carmas123 avatar Sep 04 '17 07:09 carmas123

Sorry...but again...my solution does not work

carmas123 avatar Sep 04 '17 08:09 carmas123

using kapt doesn't work?

johncarl81 avatar Sep 04 '17 16:09 johncarl81

no

carmas123 avatar Sep 05 '17 09:09 carmas123

Can you provide a simple example project that I can use to diagnose?

johncarl81 avatar Sep 05 '17 15:09 johncarl81

I'm sorry but this occurs on my big project.

carmas123 avatar Sep 06 '17 17:09 carmas123

I think that the problem is like this: https://github.com/realm/realm-java/issues/4087

carmas123 avatar Sep 06 '17 17:09 carmas123

I also see that this problem does not appear when I resync gradle before run debug

carmas123 avatar Sep 06 '17 18:09 carmas123

Are you using proguard?

johncarl81 avatar Oct 01 '17 18:10 johncarl81

Same problem with carmas123

MilkBiscuit avatar Oct 30 '17 08:10 MilkBiscuit

CurrentWeatherResponse.kt

package com.cheng.weatherdemo.models

import com.google.gson.annotations.SerializedName
import org.parceler.Parcel

@Parcel
class CurrentWeatherResponse {
    val id: Long = 0
    val weather: List<WeatherCondition>? = null
    val main: MainData? = null

    @SerializedName("name")
    val cityName: String? = null
    @SerializedName("dt")
    val time: Long = 0
}

Both WeatherCondition.kt and MainData.kt both extend java.io.Serializable

And CurrentWeatherFragment.kt

...
class CurrentWeatherFragment : Fragment() {
    private var currentWeather: CurrentWeatherResponse? = null

    override fun onSaveInstanceState(outState: Bundle?) {
        super.onSaveInstanceState(outState)

//        outState!!.putParcelable(KEY_CURRENT_WEATHER, Parcels.wrap<CurrentWeatherResponse>(currentWeather))
        outState!!.putParcelable(KEY_CURRENT_WEATHER, Parcels.wrap(currentWeather))
    }

    ...
}

10-30 04:37:40.223 2027-2027/com.cheng.weatherdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cheng.weatherdemo, PID: 2027
org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for com.cheng.weatherdemo.models.CurrentWeatherResponse, verify that your class is configured properly and that the Parcelable class com.cheng.weatherdemo.models.CurrentWeatherResponse$$Parcelable is generated by Parceler.
 at org.parceler.Parcels$ParcelCodeRepository.get(Parcels.java:153)
 at org.parceler.Parcels.wrap(Parcels.java:72)
 at org.parceler.Parcels.wrap(Parcels.java:56)
 at com.cheng.weatherdemo.ui.TodayWeatherFragment.onSaveInstanceState(TodayWeatherFragment.kt:67)
 at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:2526)
 at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:2862)
 at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:2923)
 at android.support.v4.app.FragmentController.saveAllState(FragmentController.java:125)
 at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:528)
 at android.support.v7.app.AppCompatActivity.onSaveInstanceState(AppCompatActivity.java:509)
 at com.cheng.weatherdemo.ui.MainActivity.onSaveInstanceState(MainActivity.kt:43)
 at android.app.Activity.performSaveInstanceState(Activity.java:1414)
 at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1300)
 at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:4541)
 at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4492)
 at android.app.ActivityThread.-wrap19(ActivityThread.java)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:154)
 at android.app.ActivityThread.main(ActivityThread.java:6119)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

MilkBiscuit avatar Oct 30 '17 08:10 MilkBiscuit

Note: If I change CurrentWeatherResponse.kt to CurrentWeatherResponse.java, everything works fine.

MilkBiscuit avatar Oct 30 '17 08:10 MilkBiscuit

If anyone can put together a simple demonstration project and share it on github it would help me diagnose the issue.

johncarl81 avatar Oct 31 '17 16:10 johncarl81

Use mine:

https://github.com/MilkBiscuit/WeatherDemo

You can see the problem on development branch when you rotate in MainActivity, it will crash in CurrentWeatherFragment.onSaveInstanceState().

master branch works fine because ForecastResponse and CurrentWeatherResponse class was written in java.

MilkBiscuit avatar Nov 01 '17 02:11 MilkBiscuit

Fantastic @MilkBiscuit, I'll take a look.

johncarl81 avatar Nov 01 '17 04:11 johncarl81

Error:(33, 20) error: package org.parceler does not exist I have found the same issue as i upgraded to buildtool 3.0.0 with API 26.1.0 support

jjhesk avatar Nov 13 '17 03:11 jjhesk

org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for , verify that your class is configured properly and that the Parcelable class $$Parcelable is generated by Parceler. at org.parceler.Parcels$ParcelCodeRepository.get(Parcels.java:153)

tomtharakan avatar Nov 20 '17 10:11 tomtharakan

I'm having the same issue(when I run debug). I tried to fix it by changing annotationProcessor to kapt in my build.gradle file, but when I do that I get a series of errors in the gradle console that suggest that none of the annotations are now being read (i.e. that parceler is not working at all). Has anyone else had that issue when they'd switched from annotationProcessor to kapt?

LorienOlive avatar Dec 14 '17 22:12 LorienOlive

@MilkBiscuit, I was able to get Parceler working by chancing the build scope to kapt:

dependencies {
    ...
    annotationProcessor 'org.projectlombok:lombok:1.14.8'
    kapt 'org.parceler:parceler:1.1.9'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

The result is still an error, but you'll need to resolve these in kotlin:

> Task :app:compileDebugJavaWithJavac
app: Original kapt is deprecated. Please add "apply plugin: 'kotlin-kapt'" to your build.gradle.
Processor path was modified by kapt. Previous value = configuration ':app:debugAnnotationProcessorClasspath'
Destination for generated sources was modified by kapt. Previous value = /mnt/hd1/home/john/dev/WeatherDemo/app/build/generated/source/apt/debug
error: Parceler: No @ParcelConstructor annotated constructor and no default empty bean constructor found.
error: Parceler: Unable to find read/write generator for type com.cheng.weatherdemo.models.ForecastResponse.City for com.cheng.weatherdemo.models.ForecastResponse.city
error: Parceler: Unable to find read/write generator for type java.util.List<com.cheng.weatherdemo.models.ThreeHourForecast> for com.cheng.weatherdemo.models.ForecastResponse.list
3 errors

johncarl81 avatar Dec 30 '17 21:12 johncarl81

@Parcel
class Person @ParcelConstructor constructor(val name: String)

Add @ParcelConstructor constructor may solve the problem.

ivotai avatar Jan 16 '18 03:01 ivotai

We fix this by replacing annotationProcessor 'org.parceler:parceler:1.1.11' with kapt 'org.parceler:parceler:1.1.11'.

enginebai avatar Jul 06 '18 11:07 enginebai

I added kaptTest "org.parceler:parceler:$parcelerVersion" to the build.gradle file which resolved the issue for me.

johnjohndoe avatar Feb 08 '19 12:02 johnjohndoe