The XPP answer did not work for me. Most of the cross-referenced answers ignore that this can be caused by other library dependencies (i.e. JARs/AARs). In my case this error was only appearing during the signed build -- unsigned builds were fine.
Running 'gradlew :[MY-PROJECT]:dependencies' shows the full dependency tree. If you find a dependency that uses a JAR or classes in the javax/java namespace, then you can add a gradle exclude statement to your dependency declaration, such as (gradle 4.1+):
api('my.favorite.dependency') {
exclude group: 'javax'
}
Then run the gradle ':dependencies' task again. You should see that the excluded dependency is now removed from the tree. If this dependency is required for compilation and not provided elsewhere, then the build*/assemble* tasks will fail. If the dependency is required at runtime and not provided elsewhere, for ex. by the OS, then the app. will compile and then fail at runtime with a "ClassNotFound" exception.
In the worst case, if the dependency tree isn't much help, then you may have to start commenting-out dependencies and the code that uses them, to find the culprit dependency. Hopefully the dependency that caused this error was barely used. Once you find the dependency that causes the error, you need to fix the situation one of two ways. Either replace the JAR/AAR with something that doesn't cause the error; or rebuild the dependency so that the javax/java classes are not exported with the JAR/AAR.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…