【问题标题】:Android Studio application module to a library moduleAndroid Studio 应用程序模块到库模块
【发布时间】:2015-02-08 18:17:50
【问题描述】:

我正在使用 Android Studio,并且我有一个应用程序模块,我想将其转换为库模块。

在我的应用程序模块build.gradle 文件中,我尝试过更改

apply plugin: 'com.android.application'

apply plugin: 'com.android.library'

还删除了我的applicationId 标签。

这给了我 gradle build 错误,我不知道如何继续。

Gradle 构建消息:

Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

其中 18 个:

error: constant expression required

我在MainActivity.java 中引用我的R.java 文件。

MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

        case R.id.action_settings: //gives error

            break;

        case R.id.action_share: //gives error

            break;

        case R.id.action_about: //gives error

            break;
    }

    return super.onOptionsItemSelected(item);
}

我一直在搜索如何将应用程序模块转换为库模块,上面应该已经解决了我的问题,所以我不知道为什么会出现这些错误。我错过了什么?

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    由于库项目中的 ADT 14 资源常量不再是最终的。 您可以在这里找到更多信息:https://stackoverflow.com/a/7840985/759007

    您应该用 if-else 语句替换 switch。如果您使用的是 IntelliJ/Android Studio,您可以在 switch 上按 Alt + Enter 并选择 Replace 'switch' with 'if'。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 2017-12-10
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      相关资源
      最近更新 更多