【问题标题】:Incorrect Android Project Structure in Android Studio; Only one build.gradle fileAndroid Studio 中的 Android 项目结构不正确;只有一个 build.gradle 文件
【发布时间】:2016-12-16 05:13:24
【问题描述】:

我正在使用 Android Studio,并且正在尝试将 FireBase 集成到我的应用程序中。为此,我需要在项目的根 build.gradle 和模块的 build.gradle 中添加依赖项。但我知道我的项目中只有一个 build.gradle。当我在同一个 build.gradle 中添加所有内容(FireBase 的依赖项)时,它不起作用。

所以我知道它与 build.gradle 有关。 Here's the project structure screenshot 。可能项目是从eclipse导入的。有什么方法可以让我拥有 2 个 build.gradle 文件而无需再次创建项目?

这篇文章与Android Project Structure is incorrect; only one build.gradle有相似之处。 请不要将其标记为重复。因为在上面的链接中,答案是使用单个 build.gradle。但就我而言,我需要 2 build.gradle 才能继续进行。由于我没有足够的声誉,我无法评论该帖子。对不起。请帮忙。

这是我唯一的 build.gradle 的样子:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        //FireBase dependency
        //classpath 'com.google.gms:google-services:3.0.0'
    }
}
apply plugin: 'android'



dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    //FireBase dependency
    compile 'com.google.firebase:firebase-messaging:9.6.1'
    compile 'com.google.firebase:firebase-core:9.6.1'
}
//FireBase
//apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 21
    buildToolsVersion '23.0.3'
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    lintOptions {
        abortOnError false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    productFlavors {
        x86 {
            ndk {
                abiFilter "x86"
            }
        }
        arm {
            ndk {
                abiFilters "armeabi-v7a", "armeabi"
            }
            minSdkVersion 19
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
    }
    defaultConfig {
        minSdkVersion 19
        applicationId "com.nytshift.eym.pas"
    }
}

【问题讨论】:

  • 伙计们,有人可以帮帮我吗?
  • 你使用的是 Android stuido 还是 eclipse ?
  • @animal,我正在使用 Android Studio。该项目可能是从 Eclipse 导入的。我相信这就是为什么我只有一个 build.gradle。我也想再买一个。
  • 你选择的项目结构是Android还是Project
  • @animal 双向。在帖子中提到的屏幕截图中,它是项目结构。请查看我提到的关于 build.gradle 的另一篇文章的链接。 Fabio 说可以生成 2 个 build.gradles。

标签: android-studio android-gradle-plugin build.gradle


【解决方案1】:

你有两个毕业生。您需要从左上角更改文件系统的视图。改成“安卓”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-16
    • 1970-01-01
    • 2013-10-14
    • 2016-12-28
    相关资源
    最近更新 更多