3

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?

John Ericksen
  • 10,995
  • 4
  • 45
  • 75
Gustavo Matias
  • 3,508
  • 3
  • 27
  • 30
  • Gustavo, what are you seeing? I was able to build and deploy to my phone and emulator. Are you using Maven outside of Android Studio to build on the Command Line? – John Ericksen Jul 16 '13 at 03:03
  • Hi johncarl, I'm actually using Gradle with Android Studio. but I'm not trying to run it from command line, I'm running it from android studio with that run button. so would it only work from command line? I really don't mind as long as it works, but unfortunately Transfuse docs only provided the maven version on how to run the app from command line. – Gustavo Matias Jul 16 '13 at 03:15
  • I haven tried it with Gradle yet, but I might as well give it a shot. Do you have an example you can share on github or something? – John Ericksen Jul 16 '13 at 03:17

2 Answers2

5

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.

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. 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

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

    android {
        ...
        sourceSets.main {
            manifest.srcFile 'AndroidManifest.xml'
        }
    }
    
  4. 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'
    
  5. Finally add transfuse and transfuse-api:

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

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

Edit:

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

Second Edit:

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

John Ericksen
  • 10,995
  • 4
  • 45
  • 75
  • woww Thank you so much!! sorry for not getting back to you.. got busy with other stuff. anyway, for some reason I'm getting "Gradle: : Annotation processor 'org.parceler.ParcelAnnotationProcessor' not found." any ideas? – Gustavo Matias Jul 21 '13 at 15:07
  • also got two other warnings: "Gradle: : File for type 'dummy1374419125337' created in the last round will not be subject to annotation processing." and "Gradle: : Unclosed files for the types '[dummy1374419124436, dummy1374419125337]'; these types will not undergo annotation processing" – Gustavo Matias Jul 21 '13 at 15:07
  • I didn't mean to add the ParcelerAnnotationProcessor, I've removed it from the answer and that should avoid the error you mentioned. As for the warnings they are benign and actually the unclosed files warning is necessary for Transfuse to operate. I'll look at muting some of them if possible. – John Ericksen Jul 21 '13 at 20:40
  • awesome! I'm not getting the warnings anymore after removing that processor. I think we're almost there! I can successfully build with gradle and Android Studio. the last thing I think is that when I hit "Run" using Android Studio it says "Default Activity not found" – Gustavo Matias Jul 21 '13 at 22:43
  • NVM, adding source/apt_generated/debug and source/apt_generated/release as source folders solved it! I'm so excited to start using Transfuse!! thank you soooo much! keep up the amazing work! – Gustavo Matias Jul 21 '13 at 22:51
1

For anyone struggling with "Could not find the AndroidManifest.xml" with Transfuse 3 beta 5, I fixed by adding this to my gradle file:

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
    }
}
Phil Winder
  • 116
  • 1
  • 4