【问题标题】:Unable to access interface android无法访问界面android
【发布时间】:2016-04-25 22:15:12
【问题描述】:

我正在尝试从 android studio 中的其他模块访问接口,我的项目结构如下所示

projectRoot-folder

 app-main-module //this is main app which i run
    com.mypackage.files
      MyClass.java
    build.gradle

 other-library-module //this is library module which i added
    com.package.files
      InterfaceFile.java
    build.gradle

 build.gradle
 settings.gradle

我正在为 MyClass.java 实现接口,并且工作正常,没有编译错误,但是当我按下运行时,它给出了以下错误,任何人都可以解释为什么会这样吗?感谢任何帮助,谢谢。

Error:(5, 32) error: cannot find symbol class InterfaceFile
Error:(10, 52) error: cannot find symbol class InterfaceFile
Error:(11, 5) error: method does not override or implement a method from a supertype
Error:(16, 5) error: method does not override or implement a method from a supertype
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

【问题讨论】:

  • 您必须将另一个模块声明为库并将其作为库添加到您的应用模块中
  • @Little 我已经做了

标签: java android android-studio interface


【解决方案1】:

您必须在文件 settings.gradle 中添加以下行:

include ':module2'
project(':module2').projectDir = new File(settingsDir, '../Project 2/Module2')

然后你必须在依赖树中添加你的 builde.gradle (Module: app),这一行:

compile project(':module2')

或者进入项目结构>应用>依赖,点击添加,选择3个模块依赖并选择你的模块

【讨论】:

  • 我看不懂文件的第二个参数你能解释一下吗?
  • 哪一个你不明白?在用于添加库的依赖项中添加 compile project(':module2')(例如:compile 'com.android.support:appcompat-v7:23.1.1')
  • 根据我的问题应该是 project('other-module').projectDir=new File(settingsDir,':other-module') 对吧?
  • 否则你可以像 File->new->Import Module->选择你的模块项目并在依赖项中添加 compile project(':project_name')
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-16
  • 2020-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多