简体   繁体   English

禁用某些Android Studio编译错误

[英]Disable certain Android Studio compilation errors

I'm extending a hidden java class so I run into the error 我扩展了一个隐藏的Java类,所以遇到了错误

Error:Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> class com.company.class.CustomVersion cannot access its superclass java.class.JavaVersion

However, if I don't rely on Android Studio, output a jar, and then add the jar as a dependency to the same project I don't get the above compilation error and the app can launch. 但是,如果我不依赖Android Studio,则输出一个jar,然后将该jar作为依赖项添加到同一项目中,则不会出现上述编译错误,并且该应用可以启动。 Since I'm writing my own library, I'd prefer not to have to create and export a jar every time I want to test some code change. 由于我正在编写自己的库,因此我不想每次想测试一些代码更改时都不必创建和导出jar。 Is there a way of disabling compilations errors like the above for a class? 有没有一种方法可以像上面那样禁用编译错误?

EDIT: 编辑:

For more information I was trying to extend a hidden Android class in the java.net package. 有关更多信息,我试图在java.net包中扩展一个隐藏的Android类。

Alright, so while Android Studio will complain about code in your project it won't complain if a dependency tries to access a hidden class. 好的,因此,尽管Android Studio会抱怨您项目中的代码,但如果依赖项尝试访问隐藏的类,则不会抱怨。 My solution to this problem was to create a jar file with the class in question and add that to the gradle dependencies file as with the provided keyword. 我对这个问题的解决方案是使用相关的类创建一个jar文件,并将其添加到gradle依赖文件中,就像提供的关键字一样。

dependencies {
    provided files('libs/hiddenClassDependency.jar')
}

With this your Android Studio project will build fine. 有了这个,您的Android Studio项目将可以正常运行。 When someone else uses your build product (I have mine as a jar) it'll use the hidden Android class that you couldn't access in the IDE. 当其他人使用您的构建产品(我的罐子是我的)时,它将使用您无法在IDE中访问的隐藏Android类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM