Rules and limits
What gets transformed, the mapping check and what is not covered
- Debug builds by default. Debuggable variants are instrumented. A non-debuggable build type, such as staging, is instrumented only when listed in
nonDebuggableBuildTypes(Options). Release builds that aren't listed contain no hooks. dari-noopis safe. It ships pass-through hooks, so a debuggable variant built againstdari-noopruns normally and records nothing.- Scope. By default only the module's own classes are rewritten.
- A bridge inside a third-party AAR needs
scope = InstrumentationScope.ALL. That re-dexes every AAR in the app; a cold build took about 5 minutes longer in testing. - A bridge in another module of your project needs the plugin applied in that module.
- A bridge inside a third-party AAR needs
- Manual logging still works. The plugin only touches mapped methods. If a mapped method already calls
DariInterceptor, the plugin skips that method and prints a build warning. It checks only that method's own body: a manual call elsewhere on the same path, such as in a handler, is recorded a second time. Use one way per bridge. - Mapping check. The build fails when a mapping names a class or method that isn't in the code. See Mapping check below.
- Not covered.
- Calls made through reflection.
androidx.webkitmessage channels (addWebMessageListener,WebMessagePort).- Values computed inside the method body. Only the method's parameters can be mapped.
- The re-entries a
suspendfunction receives when it resumes (withnullarguments). Only the first call is recorded.
Mapping check
A mapping whose class or method name doesn't match the code still builds, and then records nothing. A typo or a later rename is easy to miss that way, so the plugin checks every mapping against the compiled classes and fails the build instead.
When it runs
Each instrumented variant gets a dariCheck<Variant>Mappings task, such as dariCheckDebugMappings: every debuggable variant, plus the build types in nonDebuggableBuildTypes. Other release variants and modules without mappings get none.
| Task | Runs the check |
|---|---|
assembleDebug, including Android Studio's Run | Yes |
installDebug, bundleDebug | Yes |
bundleDebugAar in a library module | Yes |
check | Yes, for every instrumented variant |
testDebugUnitTest and other test tasks | No |
assembleRelease | No, unless release is in nonDebuggableBuildTypes |
To run it alone:
./gradlew :app:dariCheckDebugMappingsThe task is cached. It runs again only when the compiled classes or the mappings change.
What fails
- Missing class. The class is not among the module's compiled classes. With
scope = InstrumentationScope.ALLin an app module, the app's dependencies are searched too. Nested classes may use.or$. - Missing method. The class declares no method of that name with a body. Abstract and native methods don't count, and neither does an inherited method the class doesn't override. The plugin only instruments a body the class declares itself.
The error lists every failing mapping in the form you wrote it, with similar class or method names:
Execution failed for task ':app:dariCheckDebugMappings'.
> Dari: 2 mapping(s) match no code, so they would record nothing:
- dari { webToAppRequest("com.example.Brige", "onBridgeRequest") }: no class com.example.Brige in this module. Did you mean com.example.Bridge? A class in another module needs the plugin applied in that module; one in a library needs scope = InstrumentationScope.ALL.
- dari { webToAppResponse("com.example.MainActivity", "sendResponse") }: com.example.MainActivity has no method 'sendResponse' with a body. Did you mean sendResponseToWeb?
Fix the class or method name, or set dari { failOnUnmatchedMapping = false } to only warn.Warn instead of failing
dari {
failOnUnmatchedMapping = false // default: true
}The same messages are printed as warnings and the build goes on. Those mappings record nothing. Because the task is cached, the warnings only show again when the classes or the mappings change.
Limits
- Each variant is checked against its own classes. A bridge that exists only in one flavor's or build type's source set fails the check in the other instrumented variants. For now, the only way around this is
failOnUnmatchedMapping = false. - The check confirms that the class and method exist, not what was rewritten. To list the rewritten methods, build with
--infoand look forDari: instrumented.