Configure gradle.properties android.enableAapt=false on travis yml file
Asked Answered
M

2

9

In my android's gradle.properties I have the following:

android.enableAapt2=false

My gradle.properties is located in my ~/.gradle/gradle.properties in my local machine.

I am wondering how I can add android.enableAapt=false to my yml file.

I tried to add it under global but that didn't work there was no errors but in robolectric it needs to be set if you are using gradle:3.0.0-beta3.

language: android

jdk: oraclejdk8

env:
  global:
    - ANDROID_TARGET=android-25
    - ANDROID_ABI=armeabi-v7a
    - android.enableAapt2=false

android:
  components:
  - tools
  - platform-tools
  - build-tools-25.0.3
  - android-25
  - extra-android-m2repository
  - sys-img-${ANDROID_ABI}-${ANDROID_TARGET}


licenses:
  - android-sdk-license-.+
  - '.+'

script:
    - ./gradlew --daemon build jacocoTestReport --info

after_success:
    - bash <(curl -s https://codecov.io/bash)

Below is the configuration file that is on travis-ci

{
  "language": "android",
  "jdk": "oraclejdk8",
  "android": {
    "components": [
      "tools",
      "platform-tools",
      "build-tools-25.0.3",
      "android-25",
      "extra-android-m2repository",
      "sys-img-${ANDROID_ABI}-${ANDROID_TARGET}"
    ]
  },
  "licenses": [
    "android-sdk-license-.+",
    ".+"
  ],
  "script": [
    "./gradlew --daemon build jacocoTestReport --info"
  ],
  "after_success": [
    "bash <(curl -s https://codecov.io/bash)"
  ],
  "global_env": "ANDROID_TARGET=android-25 ANDROID_ABI=armeabi-v7a android.enableAapt2=false",
  "group": "stable",
  "dist": "precise",
  "os": "linux"
}

Class under test:

public class RecipeListViewHolderTest extends BaseRobolectricTestRunner {
    @Inject Map<Integer, RecipeListViewHolderFactory> viewHolderFactories;
    @Inject @LayoutRes int recipeItem; /* This is injected return R.layout.recipe_item; */

    private RecipeListViewHolder recipeListViewHolder;

    @Before
    public void setup() {
        getTestComponent().inject(RecipeListViewHolderTest.this);
        final Context context = ShadowApplication.getInstance().getApplicationContext();

        final View view = View.inflate(
                context,
                recipeItem,
                new LinearLayout(context));

        recipeListViewHolder = viewHolderFactories.get(Constants.RECIPE_LIST).create(view);
        assertThat(recipeListViewHolder, is(notNullValue()));
    }

    private Recipe createRecipeData() {
        Recipe recipe = new Recipe();
        recipe.setName("Test Brownies");
        recipe.setServings(10);

        return recipe;
    }

    @Test
    public void testRecipeDataIsPopulated() {
        recipeListViewHolder.populateDate(createRecipeData());

        assertThat(recipeListViewHolder.tvQuantity.getText().toString(), is("Quantity: 10"));
        assertThat(recipeListViewHolder.tvRecipeName.getText().toString(), is("Test Brownies"));
    }
}

Robolectric:

@Config(constants = BuildConfig.class,
        sdk = Build.VERSION_CODES.LOLLIPOP,
        packageName = "me.androidbox.busbybaking",
        application = BusbyBakingApplication.class)
@RunWith(RobolectricTestRunner.class)
public abstract class BaseRobolectricTestRunner {

    protected TestBusbyComponent getTestComponent() {
        return DaggerTestBusbyComponent.builder()
                .mockRecipeListModule(new MockRecipeListModule())
                .mockRecipeSchedulersModule(new MockRecipeSchedulersModule())
                .build();
    }
}

The travis-ci error log:

me.androidbox.busbybaking.recipieslist.RecipeListViewHolderTest > testRecipeDataIsPopulated FAILED
    android.content.res.Resources$NotFoundException: me.androidbox.busbybaking:layout/recipe_item
        at org.robolectric.shadows.ShadowAssetManager.loadXmlResourceParser(ShadowAssetManager.java:391)
        at org.robolectric.shadows.ShadowResources.loadXmlResourceParser(ShadowResources.java:211)
        at android.content.res.Resources.loadXmlResourceParser(Resources.java)
        at android.content.res.Resources.getLayout(Resources.java:1049)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at android.view.View.inflate(View.java:18415)
        at me.androidbox.busbybaking.recipieslist.RecipeListViewHolderTest.setup(RecipeListViewHolderTest.java:41)

I think that the travis-ci cannot find where the res folder is as the layout/recipe_item cannot be found:

 android.content.res.Resources$NotFoundException: me.androidbox.busbybaking:layout/recipe_item
Martellato answered 31/8, 2017 at 13:54 Comment(4)
Are you sure you are not mixing android.enableAapt with android.enableAapt2? You cannot disable AAPT, you can disable AAPT2.Evocative
Also you have written android.enableApat=false in your yml file, it should be Aapt instead of Apat.Evocative
That was my mistake in the travis-ci. It was a typo. I have updated my question accordingly.Martellato
I have updated my question with the exact error I am getting. To answer your question on ~/.gradle/gradle.properties is because I have set the build ramdisk android.buildCacheDir=/mnt/ramdisk/buildCacheand I didn't want to export that to travis-ci. However, I have moved the gradle.properties to my project director and removed that line. I am trying again to build on travis-ciMartellato
E
6

I think the problem is that you are disabling AAPT2 in global properties file ~/.gradle/gradle.properties instead of project properties file /yourproject/gradle.properties.

Evocative answered 4/9, 2017 at 16:7 Comment(2)
That worked for travis-ci, thanks. However, just a quick question. In my local project will android studio use the global ~/.gradle/grade.properties or the local ~/myProject/gradle.properties?Martellato
Global properties has precedence over local properties, i.e. if you define variable with the same name in both global and project gradle.properties file, than the one from global will have higher priority.Evocative
S
0

It could be, that you have copied the name of the gradle.properties file from this official tweet:

https://twitter.com/androidstudio/status/875311569219006464

Unfortunettely the text gradle.propertіes was written with cyrilic 'i' :

echo 'gradle.propertіes' | hexdump -C

00000000 67 72 61 64 6c 65 2e 70 72 6f 70 65 72 74 d1 96 |gradle.propert..| 00000010 65 73 0a |es.|

0xd196 is in UTF8 'CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I'.

In this case the file will not be recognized and used.

Sisk answered 23/11, 2017 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.