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

查看:310
本文介绍了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天全站免登陆