Navigation Library inflator throws ClassNotFoundException for data class

Just faced problem similar to this issue and I got realized I didn't set up any proguard rules. Here's additional information that might be helpful.

The following codes are found in navigation component version 2.2.0-rc02.

// NavType.java
try {
    String className;
    if (type.startsWith(".") && packageName != null) {
        className = packageName + type;
    } else {
        className = type;
    }

    if (type.endsWith("[]")) {
        className = className.substring(0, className.length() - 2);
        Class<?> clazz = Class.forName(className);
        if (Parcelable.class.isAssignableFrom(clazz)) {
            return new ParcelableArrayType(clazz);
        } else if (Serializable.class.isAssignableFrom(clazz)) {
            return new SerializableArrayType(clazz);
        }
    } else {
        Class<?> clazz = Class.forName(className);
        if (Parcelable.class.isAssignableFrom(clazz)) {
            return new ParcelableType(clazz);
        } else if (Enum.class.isAssignableFrom(clazz)) {
            return new EnumType(clazz);
        } else if (Serializable.class.isAssignableFrom(clazz)) {
            return new SerializableType(clazz);
        }
    }
    throw new IllegalArgumentException(className + " is not Serializable or "
            + "Parcelable.");
} catch (ClassNotFoundException e) {
    throw new RuntimeException(e);
}

You can see it looks for classes using Class.forName(String) method. So keeping their names is enough.

# Instead of -keep
-keepnames class com.package.app.data.model.** { *; }

And if packageName is provided, you can omit package name from value of argType attribute, but sadly it won't work if you use some application id suffixes depending on build variants. (So do not omit package name from argType)


After all, it was a known bug in Android Studio.

Since the release of 1.0.0-alpha09, something changed in the way they handled inner classes.

If a parcelable is an inner class, it has to be written like: com.domain.app.User$Full where Full is the parcelized object.

If you want to read more about this, check out this answer on Google's Issue Tracker: https://issuetracker.google.com/u/2/issues/123614632#comment4