产品风味[从eclipse迁移到android studio] [英] Product flavour [Migrating from eclipse to android studio]

查看:82
本文介绍了产品风味[从eclipse迁移到android studio]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将我的应用程序从eclipse迁移到了android studio,现在我正尝试运行产品风味. 我一直在 http://blog.robustastudio.com/mobile-development/android/building-multiple-editions-of-android-app-gradle/

I have migrated my app from eclipse to android studio, and now I was attempting to run product flavours. I have been following the blog at http://blog.robustastudio.com/mobile-development/android/building-multiple-editions-of-android-app-gradle/

以下是我从eclipse导入时的构建结构.

Following is my build structure when imported from eclipse.

我可以在构建变体窗口中看到变体.

I am able to see the variants in the build variants window.

以下是build.gradle

Following is the build.gradle

应用插件:"com.android.application"

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':volley')
    compile 'com.google.android.gms:play-services-gcm:7.5.0'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'com.android.support:appcompat-v7:21.0.+'
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // 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')
    }

    defaultConfig {
        multiDexEnabled true
    }

    buildTypes {

        release {
            minifyEnabled true;
            proguardFiles getDefaultProguardFile('proguard-project.txt');
        }
    }

    productFlavors {

        demo {
            applicationId "com.demo.app"
        }

    }

    lintOptions {
        checkReleaseBuilds false;
        abortOnError false;
    }
}

我希望Constants.java文件可用于不同的风味,因为其各自的风味具有不同的值.

I want the Constants.java file to be available for different flavours as it has different values for the respective flavours.

以下是一般工作室项目中看到的构建结构

Following is the build structure as seen in general studio projects

app/
|--libs/
|--src/
   |--vanilla/
   |  |--java/
   |     |--com/example/
   |        |--Flavor.java
   |--strawberry/
   |  |--java/
   |     |--com/example/
   |        |--Flavor.java
   |--main/
      |--java/
      |  |--...
      |--res/
      |  |--...
      |--AndroidManifest.xml

但是从Eclipse迁移时的结构似乎完全不同. 我试图在src [demo/com.demo.app]中建立一个目录来检查风味变量.但它不起作用.有人可以指导我吗?我如何为从Eclipse迁移的项目提供产品风味支持

But the structure when migrated from eclipse seems to be totally different. I tried to make a directory in src [demo/com.demo.app]to check the flavour variant. But its not working. Can anyone guide me on this ? How do i go about including product flavour support for projects migrated from eclipse

推荐答案

从Eclipse导入项目时,Android Studio会保留相同的文件夹结构,因此您的源代码不会移动太多.

When you import a project from Eclipse, Android Studio keeps the same folder structure so your source doesn't move around too much.

这意味着您将无法使用默认的源位置.这就是为什么您的build.gradle具有sourceSets闭包:

This means that you won't be able to use the default source locations. This is why your build.gradle has the sourceSets closure:

sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
}

此块为所有默认代码(main配置)设置位置.

This block sets up the location for all of your default code (the main configuration).

如果您不想更改项目结构,则可以在sourceSets中添加另一个块以符合您的口味.下面的示例将允许您将demo风格的所有代码放在demo/src下:

If you don't want to change your project structure, you can add another block within sourceSets for your flavor. The following example will allow you to put all the code for your demo flavor under demo/src:

sourceSets {
        main {}
        demo {
            manifest.srcFile 'demo/AndroidManifest.xml'
            java.srcDirs = ['demo/src']
            resources.srcDirs = ['demo/src']
            aidl.srcDirs = ['demo/src']
            renderscript.srcDirs = ['demo/src']
            res.srcDirs = ['demo/res']
            assets.srcDirs = ['demo/assets']
        }
}

另一种选择是完全删除sourceSets闭包,并更新您的项目结构,使其与Gradle支持的项目的标准结构相匹配.

The other alternative is to remove the sourceSets closure completely and update your project structure to match the standard structure for Gradle-backed project.

这篇关于产品风味[从eclipse迁移到android studio]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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