在我的机器人android.enableAapt2=false
中,我有以下内容:
gradle.properties
我的~/.gradle/gradle.properties
位于我本地计算机的android.enableAapt=false
。
我想知道如何将robolectric
添加到我的yml文件中。
我尝试在全球范围内添加它,但没有错误,但在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)
则需要设置它。
{
"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"
}
以下是travis-ci上的配置文件
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"));
}
}
待测班级:
@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();
}
}
Robolectric:
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错误日志:
android.content.res.Resources$NotFoundException: me.androidbox.busbybaking:layout/recipe_item
我认为travis-ci无法找到res文件夹的位置,因为找不到layout / recipe_item:
{{1}}
答案 0 :(得分:6)
我认为问题在于您在全局属性文件~/.gradle/gradle.properties
中禁用AAPT2而不是项目属性文件/yourproject/gradle.properties
。
答案 1 :(得分:0)
可能是,您已从此官方推文中复制了gradle.properties文件的名称:
https://twitter.com/androidstudio/status/875311569219006464
不幸的是,文本gradle.propertіes是用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
是UTF8'CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I'。
在这种情况下,将无法识别和使用该文件。