Ну, решил сам, используя процессор аннотаций.
Создайте аннотацию, которая применяется к классу, который должен содержать конструктор:
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
annotation class KeepInit
Процессор аннотации для построения проекта:
fun enclosingType(el: Element): Element {
var e: Element? = el
var c: TypeElement?
do {
e = e?.enclosingElement
c = e as? TypeElement
} while (e != null && c == null)
return c ?: el
}
val enclosing = enclosingType(elementOfCustomAnnotation)
if (enclosing.annotationMirrors.none { it.annotationType.toString() == "xxx.foo.bar.KeepInit" }) {
throw Exception("must add @KeepInit to class: $enclosing")
}
Правило Proguard:
-keepclassmembers,allowobfuscation @xxx.foo.bar.KeepInit class * {
<init>(...);
}
Пример:
@KeepInit
class SomeClass(
@SomeCustomAnnotation("id") private val id: String,
@SomeCustomAnnotation("title") private val title: String
)