johncarl81 / transfuse

:syringe: Transfuse - A Dependency Injection and Integration framework for Google Android
http://androidtransfuse.org/
Apache License 2.0
220 stars 28 forks source link

Manifest generation #158

Open kf4x opened 9 years ago

kf4x commented 9 years ago

I am not sure what is happening I don't know if this is gradle, transfuse, or what. I put a project up that reproduces my problem here.

as far I can tell when i build the app i.e. gradle clean build, it successfully builds but I can not run the app there is no option to either.

I look at app/build/intermediates/manifests/full/debug/manifest-debug.xml and contains 2 application tags

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<manifest package="com.javier.test.app" android:versionCode="1" android:versionName="1.0" t:tag="+" xmlns:t="http://androidtransfuse.org" xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/>
    <application/>
    <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name=".MainApplicationApplication" t:tag="+,ab,i,l,n">
        <activity android:label="@string/app_name" android:name=".MainActivityActivity" t:tag="+,l,n">
            <intent-filter t:tag="+">
                <action android:name="android.intent.action.MAIN" t:tag="+,n"/>
                <category android:name="android.intent.category.LAUNCHER" t:tag="+,n"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

anyway I got curious and pull apart the apk generated by the grade build, and the only application tag in found is the empty one. I am at a loss of what I have done.

johncarl81 commented 9 years ago

Shoot. I'm wondering if Transfuse is adding two applications. I'll investigate the code angle, but in the mean time can you update your manifest to include the application like so:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<manifest package="com.javier.test.app" android:versionCode="1" android:versionName="1.0" t:tag="+" xmlns:t="http://androidtransfuse.org" xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/>
    <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name=".MainApplicationApplication" t:tag="+,ab,i,l,n">
        <activity android:label="@string/app_name" android:name=".MainActivityActivity" t:tag="+,l,n">
            <intent-filter t:tag="+">
                <action android:name="android.intent.action.MAIN" t:tag="+,n"/>
                <category android:name="android.intent.category.LAUNCHER" t:tag="+,n"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
kf4x commented 9 years ago

I spent a little more time digging around. I can't find any problems with transfuse. Transfuse is generating the manifest correctly but android-apt is not configured correctly.

If I do as you say the app builds and runs normally.

Thanks John for looking at this!

johncarl81 commented 9 years ago

That's good news @javierchavez. Can you try building with transfuse under the provided scope instead of android-apt, and does it do the same thing to an empty Manifest?

kf4x commented 9 years ago

I just tried provided scope and that brought issues with merging manifests and the new android plugin... so in short I could not get that to properly compile

I am going to use this advice until I can figure out manifest variants because I can't figure out what is going on in there.

kf4x commented 8 years ago

So unfortunately this is still an issue.

It has to do with the new Manifest Merger. The Merger gets a hold of it first then adds a tag. I have had success forcing transfuse to fill it in first but its not a very nice solution.

I created a test similar to this with the empty tag. The Manifest object had 2 Applications and sure enough transfuse is treated it as a unique tag and not merging.

I couldn't immediately see any way to either user the marshaller or somewhere in the Manifest model treat an empty tag as mergeable or to not write it when serializing.

Also I did read here that <application> can only appear once 👎. But that might a good way to simplify it.

johncarl81 commented 8 years ago

Trying to run your example app mentioned above I'm getting the following error during the build:

...
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
 Position 1 : Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
 Position 1 : Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

:app:processDebugResources FAILED

FAILURE: Build failed with an exception.

If you're having trouble, there is always the option to turn off manifest management or log out the manifest for manual handing:

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        transfuseManifestProcessing "off" // "log"
    }
}

To the issue.. what should Transfuse be doing here? I wonder if we could use the Manifest Merger to our advantage, having it merge the Transfuse specific components into the final AndroidManifest.xml.

kf4x commented 8 years ago

@johncarl81 I actually didn't think about turning it off. I guess I would have to generate the manifest, merge the one generated by transfuse and google by hand. Then turn it off, and manage it form there.

I tried to add a few cases on the manifest-merge branch

johncarl81 commented 8 years ago

Hmm, your branch works for me ootb: screenshot_2016-04-30-23-29-31

kf4x commented 8 years ago

Yeah I left the manifest put together. I need to write some more comments. I realized after i sent it I needed to be a little more clear with the repro.

kf4x commented 8 years ago

Ok I split it up into branches for brevity

johncarl81 commented 8 years ago

These are great failure cases. Would you like to offer a fix? Is there anything I can provide to help you along?

kf4x commented 8 years ago

Yes I'll spend some time to do a little more investigation to offer some potential approaches for critique. I like you're idea of using the manifest merge to our advantage.