Android 项目结构不正确;只有一个 build.gradle [英] Android Project Structure is incorrect; only one build.gradle

查看:26
本文介绍了Android 项目结构不正确;只有一个 build.gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构不正确.我需要一个顶级的 build-gradle,以及一个包含它自己的 build.gradle 的相同级别的模块.

I have an incorrect project structure. I need a top-level build-gradle, and a module on the same level that contains its own build.gradle.

查看现在组织方式的图片.你看到的几乎是两个不同的层次合并到了on.e.这里的build.gradle是项目中唯一的一个.您看到的那个有注释,它是顶级版本.

See picture of how it is organized now. What you see is almost two different levels merged into on.e The build.gradle here is the only one in the project. The one you see has the note that it is the top-level version.

解决这个问题的正确方法是什么?我需要重新导入还是可以重新组织?

What is the correct way to straighten this out? Do I need to reimport or can I reorganize it?

其他信息,我安装了 Gradle 2.10.

Other info, I have Gradle 2.10 installed.

更多信息

通常我的顶级 Gradle 文件包含如下内容:

Usually I have my top-level Gradle file that contains something like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

但是在上面的设置中,没有第二个 Gradle 文件,我该把其他信息放在哪里 ...例如:

But in the setup above, without having that second Gradle file, where do I put the other info ... for example:

apply plugin: 'com.android.application'


repositories {
    mavenCentral()
    maven {
        url "https://jitpack.io"
    }
}



android {

   defaultConfig {
       // edited
   }

    dependencies {
       // edited
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

apply plugin: 'com.google.gms.google-services'

当我运行程序时,出现此错误:

When I run the program, I get this error:

Error:A problem was found with the configuration of task ':checkDebugManifest'.
> File 'C:\--\src\main\AndroidManifest.xml' specified for property 'manifest' does not exist.

这有关系吗?

推荐答案

这种方式仍然假设没有 OP 要求的额外模块的扁平层次结构,但由于它基于我自己的 Eclipse 到 AS 迁移,我知道它有效... 对我来说.

This way is still assuming a flat hierarchy without the extra module asked by OP, but since it's based on my own Eclipse to AS migration I know it worked... for me.

要在不移动您需要的文件的情况下识别 Eclipse 默认值:

To recognize eclipse defaults without moving the files you need this:

android {
  defaultConfig {

     sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
        test.java.srcDirs = ['src/test/java', 'build/generated/source/debug']
    }

这很可能允许您使用具有相同文件夹的 eclipse 和 Android Studio.

This will most likely allow you to use both eclipse and Android Studio with the same folders in place.

第二种方法是不改变 gradle 而是移动文件夹,以便 gradle 找到它期望的东西.

The second way is about not changing gradle but moving folders so gradle finds things where it expects to.

  1. 移动AndroidManifest.xml,它必须进入src/main
  2. res移动到src/main/res
  3. src/com 移动到 src/main/java/com(你能确认你的 com 文件夹当前在哪里吗?
  1. move AndroidManifest.xml, it must go into src/main
  2. move res into src/main/res
  3. move src/com into src/main/java/com (can you confirm where is your com folder currently?

您可以移动文件或将 gradle 定向到它们所在的位置,这是您的选择 - 但不要同时进行.我唯一不记得的步骤是 build/generated/source/debug 用于测试,我不记得我是否使用了它,因为我使用了 groovy 或者它是另一个 eclipse maven/AS gradle不匹配.

You can either move files or direct gradle to where they are, it's your choice - but don't do both. The only step I don't remember is the build/generated/source/debug for test, I can't remember if I used that because I use groovy or if it was another eclipse maven/AS gradle mismatch.

这篇关于Android 项目结构不正确;只有一个 build.gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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