简体   繁体   English

Android Studio Build APK ClassNotFoundException

[英]Android Studio Build APK ClassNotFoundException

My app is split in many projects, which are included as a dependency in my main library which is a dependency in my app. 我的应用程序分为许多项目,这些项目作为依赖项包含在我的主库中,而这是我的应用程序中的依赖项。

  • Project Main 项目主体

    • Module App 模块应用
      • Dependencies 依赖
        • MainLibrary Module 主库模块
    • Module MainLibrary 模块主库
      • Dependencies 依赖
        • Project X X计划
        • Project Y Y项目
  • Project X X计划

    • Module 1 模块1
    • Module 2 模块2
  • Project Y Y项目
    • Module 1 模块1

My first problem is, that my dependency to Project X is not packaged in my APK Dex File and i get a ClassNotFoundException if the app starts and the class in this module is used. 我的第一个问题是,我对Project X的依赖关系未打包在我的APK Dex文件中,如果应用程序启动并且使用了此模块中的类,则会收到ClassNotFoundException。 I declare the dependency with provided project(':beacon') 我用提供的项目声明依赖(':beacon')

The second problem is, that i have to declare the dependencies in my MainLibrary Module and in my AppModule. 第二个问题是,我必须在MainLibrary模块和AppModule中声明依赖项。 Thats twice. 多数民众赞成在两次。

Thank you for your help 谢谢您的帮助

That's what the provided dependency scope -- it uses the dependency for compiling but doesn't bundle it into the output. 这就是所provided依赖项范围-它使用依赖项进行编译,但不将其捆绑到输出中。 Use the compile scope instead. 请改用compile范围。

As for needing to declare a dependency on Project X in more than one place, that's because dependencies aren't transitive. 至于需要在多个地方声明对Project X的依赖关系,那是因为依赖关系不是可传递的。 If Module App depends on Project X , it needs to declare that explicitly and not depend on getting it through a sub-dependency. 如果Module App依赖于Project X ,则需要显式声明它,而不依赖于通过子依赖关系获取它。 That's not to say that if you use the compile scope the sub-dependency won't be included in the output, but if you want to depend on it from a parent module, it needs to declare its dependency separately. 这并不是说,如果您使用compile范围,则子依赖项将不包含在输出中,但是,如果您想从父模块中依赖它,则需要单独声明其依赖项。

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

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