在 travis yml 文件上配置 gradle.properties android.enableAapt=false
Configure gradle.properties android.enableAapt=false on travis yml file
在我的 android 的 gradle.properties
中,我有以下内容:
android.enableAapt2=false
我的 gradle.properties
位于我本地机器的 ~/.gradle/gradle.properties
中。
我想知道如何将 android.enableAapt=false
添加到我的 yml 文件中。
我试图在全局下添加它,但没有成功,没有错误,但在 robolectric
中,如果您使用 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)
下面是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 测试中:
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();
}
}
travis-ci错误日志:
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)
我认为 travis-ci 找不到 res 文件夹的位置,因为找不到 layout/recipe_item:
android.content.res.Resources$NotFoundException: me.androidbox.busbybaking:layout/recipe_item
我认为问题在于您在全局属性文件 ~/.gradle/gradle.properties
而不是项目属性文件 /yourproject/gradle.properties
.
中禁用了 AAPT2
可能是您从这条 官方 推文中复制了 gradle.properties 文件的名称:
https://twitter.com/androidstudio/status/875311569219006464
不幸的是,文本 gradle.propertіes 是用西里尔 '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
是 UTF8 'CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I'.
在这种情况下,文件将不会被识别和使用。
在我的 android 的 gradle.properties
中,我有以下内容:
android.enableAapt2=false
我的 gradle.properties
位于我本地机器的 ~/.gradle/gradle.properties
中。
我想知道如何将 android.enableAapt=false
添加到我的 yml 文件中。
我试图在全局下添加它,但没有成功,没有错误,但在 robolectric
中,如果您使用 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)
下面是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 测试中:
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();
}
}
travis-ci错误日志:
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)
我认为 travis-ci 找不到 res 文件夹的位置,因为找不到 layout/recipe_item:
android.content.res.Resources$NotFoundException: me.androidbox.busbybaking:layout/recipe_item
我认为问题在于您在全局属性文件 ~/.gradle/gradle.properties
而不是项目属性文件 /yourproject/gradle.properties
.
可能是您从这条 官方 推文中复制了 gradle.properties 文件的名称:
https://twitter.com/androidstudio/status/875311569219006464
不幸的是,文本 gradle.propertіes 是用西里尔 '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
是 UTF8 'CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I'.
在这种情况下,文件将不会被识别和使用。