Test multidex and annotations access.
This was able to reproduce a problem reported by GMM when they were listing annotations on classes used before MultiDex installation. See Bug 14233284 Change-Id: I828c92f0e382dc984b6462fab710f414138e7e02
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18"/>
|
||||
|
||||
<application
|
||||
android:name=".TestApplication"
|
||||
android:label="multidexlegacytestapp"
|
||||
>
|
||||
<activity
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
@AnnotationWithEnum2(ReferencedByAnnotationWithOtherReferences.A)
|
||||
public class Annotated {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
@AnnotationWithClass(ReferencedByClassInAnnotation.class)
|
||||
public class Annotated2 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AnnotationWithClass {
|
||||
|
||||
Class<?> value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AnnotationWithEnum {
|
||||
|
||||
ReferencedByAnnotation value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AnnotationWithEnum2 {
|
||||
|
||||
ReferencedByAnnotationWithOtherReferences value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
public interface InterfaceWithEnum {
|
||||
|
||||
ReferencedByInterface getEnum();
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package com.android.multidexlegacytestapp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.multidex.MultiDex;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -36,9 +35,6 @@ public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
MultiDex.install(getApplicationContext());
|
||||
Log.i(TAG, "Multi dex installation done.");
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
int value = getValue();
|
||||
@@ -94,4 +90,8 @@ public class MainActivity extends Activity {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getAnnotation2Value() {
|
||||
return ((AnnotationWithEnum2) TestApplication.annotation2).value().get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
public enum ReferencedByAnnotation {
|
||||
|
||||
A,
|
||||
B;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
public enum ReferencedByAnnotationWithOtherReferences {
|
||||
|
||||
A {
|
||||
private ReferencedByEnum a = new ReferencedByEnum();
|
||||
@Override
|
||||
public int get() {
|
||||
return a.hashCode();
|
||||
}
|
||||
},
|
||||
B {
|
||||
private ReferencedByEnum b = new ReferencedByEnum();
|
||||
@Override
|
||||
public int get() {
|
||||
return b.hashCode();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public abstract int get();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
public enum ReferencedByClassInAnnotation {
|
||||
|
||||
A {
|
||||
private ReferencedByEnum a = new ReferencedByEnum();
|
||||
@Override
|
||||
public int get() {
|
||||
return a.hashCode();
|
||||
}
|
||||
},
|
||||
B {
|
||||
private ReferencedByEnum b = new ReferencedByEnum();
|
||||
@Override
|
||||
public int get() {
|
||||
return b.hashCode();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public abstract int get();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
public class ReferencedByEnum {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
public enum ReferencedByInterface {
|
||||
|
||||
A,
|
||||
B;
|
||||
|
||||
}
|
||||
@@ -17,6 +17,11 @@ package com.android.multidexlegacytestapp;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
/**
|
||||
* Run the tests with: <code>adb shell am instrument -w
|
||||
com.android.multidexlegacytestapp/android.test.InstrumentationTestRunner
|
||||
</code>
|
||||
*/
|
||||
public class Test extends ActivityInstrumentationTestCase2<MainActivity> {
|
||||
public Test() {
|
||||
super(MainActivity.class);
|
||||
@@ -25,4 +30,23 @@ public class Test extends ActivityInstrumentationTestCase2<MainActivity> {
|
||||
public void testAllClassesAvailable() {
|
||||
assertEquals(3366, getActivity().getValue());
|
||||
}
|
||||
|
||||
public void testAnnotation() {
|
||||
assertEquals(ReferencedByAnnotation.B,
|
||||
((AnnotationWithEnum) TestApplication.annotation).value());
|
||||
assertEquals(ReferencedByAnnotation.B,
|
||||
((AnnotationWithEnum) TestApplication.getAnnotationWithEnum()).value());
|
||||
// Just to verify that it doesn't crash
|
||||
getActivity().getAnnotation2Value();
|
||||
|
||||
assertEquals(ReferencedByClassInAnnotation.class,
|
||||
((AnnotationWithClass) TestApplication.annotation3).value());
|
||||
// Just to verify that it doesn't crash
|
||||
ReferencedByClassInAnnotation.A.get();
|
||||
}
|
||||
|
||||
public void testInterface() {
|
||||
assertEquals(InterfaceWithEnum.class,
|
||||
TestApplication.interfaceClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.android.multidexlegacytestapp;
|
||||
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
@AnnotationWithEnum(ReferencedByAnnotation.B)
|
||||
public class TestApplication extends MultiDexApplication {
|
||||
|
||||
public static Annotation annotation = getAnnotationWithEnum();
|
||||
public static Annotation annotation2 = getSoleAnnotation(Annotated.class);
|
||||
public static Annotation annotation3 = getSoleAnnotation(Annotated2.class);
|
||||
public static Class<?> interfaceClass = InterfaceWithEnum.class;
|
||||
|
||||
public static Annotation getAnnotationWithEnum() {
|
||||
return getSoleAnnotation(TestApplication.class);
|
||||
}
|
||||
|
||||
public static Annotation getSoleAnnotation(Class<?> annotated) {
|
||||
Annotation[] annot = annotated.getAnnotations();
|
||||
if (annot.length == 1) {
|
||||
return annot[0];
|
||||
}
|
||||
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user