为什么编译时库模块中的包不存在,即使 Android Studio 没有显示代码错误? [英] Why do packages from library module does not exist upon compilation, even when Android Studio shows no errors in code?

查看:28
本文介绍了为什么编译时库模块中的包不存在,即使 Android Studio 没有显示代码错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 libs/AndEngine 文件夹中有一个库模块 (AndEngine).从中编译的代码很好.

I have a library module (AndEngine) inside my libs/AndEngine folder. The code from that compiles fine.

在我的根 settings.gradle 文件中,我有这个:

In my root settings.gradle file I have this :

include ':app:libs:AndEngine'
include ':app' 

然后在我的应用程序的 build.gradle 文件中,我在依赖项中有这个:

And then in my app's build.gradle file I have this in dependencies:

compile project('libs:AndEngine')

在我的应用程序代码中,所有导入甚至自动完成都没有任何错误.在 Android Studio 中,可以找到所有包.但是当我去编译时,我得到了大约一百个这样的错误:

INside my app's code, all of the imports and even autocompletion works without any errors at all. Inside Android Studio, all of the packages are found. But when I go to compile, I get about a hundred of these errors:

error: package org.andengine.entity.primitive does not exist
import org.andengine.entity.primitive.Rectangle;

我来自 eclipse 的 ADK,所以我是 android studio 的新手.如果有人对此问题有任何答案,我将不胜感激!

I am coming from the ADK with eclipse, so I am new to android studio. If anyone has any answers to this problem I would be very appreciative!

推荐答案

更改此行.

compile project('libs:AndEngine')

compile project(':app:libs:AndEngine')

在任何情况下,将库模块放在应用程序模块中都不是一个好主意.我建议你使用这种结构:

In any case it is not a good idea to put a library module inside the app module. I suggest you using this structure:

root
  settings.gradle
  app
    build.gradle
  libs
    AndEngine
      build.gradle

然后在你的 settings.gradle

include ':libs:AndEngine'
include ':app' 

在你的 app/build.gradle

compile project(':libs:AndEngine')

这篇关于为什么编译时库模块中的包不存在,即使 Android Studio 没有显示代码错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆