带有 Transfuse 的 Android Studio [英] Android Studio with Transfuse

查看:31
本文介绍了带有 Transfuse 的 Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在我的 android 项目中成功设置 Transfuse,但是在使用 Android Studio 运行应用程序时,它失败了.可能是因为 Manifest xml 必须为空才能让 Transfuse 处理.

I can successfully set up Transfuse in my android project but when it comes to running the app using Android Studio, it fails. Probably because the Manifest xml has to be empty for Transfuse to take care of.

有没有人把这些一起工作过?

Has anyone ever got these working together?

推荐答案

Transfuse 和 Android Studio 配合得非常好.诀窍是让 Transfuse 与 Gradle 集成.一旦您让 Gradle 工作,构建将启动注释处理器并运行 Transfuse.

Transfuse and Android Studio work remarkably well together. The trick is to get Transfuse integrated with Gradle. Once you get Gradle working, the build will just kick off the annotation processor and run Transfuse.

我在这里整理了一个示例参考项目:https://github.com/johncarl81/transfuse/tree/master/examples/gradle

I've put together an example reference project here: https://github.com/johncarl81/transfuse/tree/master/examples/gradle

以下是到达那里的程序:

Here's the procedure to get there:

  1. 让 Android Studio 生成一个新的 Android 项目
  2. 将AndroidManifest.xml文件移动到Android项目的根目录,即:~/project/src/main/AndroidManifest.xml -> ~/project/AndroidManifest.xml

  1. Have Android Studio generate a new Android project
  2. Move the AndroidManifest.xml file to the root of the Android project, ie: ~/project/src/main/AndroidManifest.xml -> ~/project/AndroidManifest.xml

在 gradle.build 文件中设置新的 AndroidManifest.xml 位置:

Setup the new AndroidManifest.xml location in the gradle.build file:

android {
    ...
    sourceSets.main {
        manifest.srcFile 'AndroidManifest.xml'
    }
}

  • 添加 APT 插件:

  • Add the APT plugin:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
            classpath 'com.android.tools.build:gradle:0.6.+'
        }
    }
    apply plugin: 'android'
    apply plugin: 'android-apt'
    

  • 最后添加 transfuse 和 transfuse-api:

  • Finally add transfuse and transfuse-api:

    dependencies {
        apt 'org.androidtransfuse:transfuse:0.2.7'
        compile 'org.androidtransfuse:transfuse-api:0.2.7'
    }
    

  • 您最终的 gradle.build 将如下所示:

    Your final gradle.build will look like this:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
            classpath 'com.android.tools.build:gradle:0.6.+'
        }
    }
    apply plugin: 'android'
    apply plugin: 'android-apt'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        apt 'org.androidtransfuse:transfuse:0.2.7'
        compile 'org.androidtransfuse:transfuse-api:0.2.7'
    }
    
    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.0"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 19
        }
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_6
            targetCompatibility JavaVersion.VERSION_1_6
        }
        sourceSets.main {
            manifest.srcFile 'AndroidManifest.xml'
        }
    }
    

    最后,您可能希望在项目配置下添加 source/apt_generated/debug 或 source/apt_generated/release 文件夹作为源文件夹.

    Finally you probably want to add the source/apt_generated/debug or source/apt_generated/release folders as source folders under the project configuration.

    第二次

    我用新的 Android-APT 插件更新了上面的例子

    I updated the above example with the new Android-APT plugin

    这篇关于带有 Transfuse 的 Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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