Reputation: 789
We have Android project which should be upgraded by adding Android-support-v7-AppCompat and Google-Play-Services_lib libraries. We added them to Ant script:
<property name="android-support-v7-appcompat-folder" value="../android-support-v7-appcompat"/>
<property name="android-support-v7-appcompat-src-folder" value="${android-support-v7-appcompat-folder}/src"/>
<property name="android-support-v7-appcompat-resource-folder" value="${android-support-v7-appcompat-folder}/res"/>
<property name="android-support-v7-appcompat-libs-folder" value="${android-support-v7-appcompat-folder}/libs"/>
<property name="google-play-services-folder" value="../google-play-services_lib"/>
<property name="google-play-services-src-folder" value="${google-play-services-folder}/src"/>
<property name="google-play-services-resource-folder" value="${google-play-services-folder}/res"/>
<property name="google-play-services-libs-folder" value="${google-play-services-folder}/libs"/>
<target name="compile" depends="resource-src, aidl">
<path id="project.javac.classpath">
<path refid="project.all.jars.path" />
<path refid="tested.project.classpath" />
</path>
<javac encoding="ascii" target="1.7" source="1.7"
debug="true" extdirs="" includeantruntime="false"
destdir="${out-classes}"
bootclasspath="${android.jar}">
<src path="${source-folder}" />
<src path="${kxml-folder}" />
<src path="${jzlib-folder}" />
<src path="${bouncycastle-folder}" />
<src path="${gen-folder}" />
<src path="${android-support-v7-appcompat-src-folder}" />
<src path="${google-play-services-src-folder}" />
<classpath>
<fileset dir="${android-support-v7-appcompat-libs-folder}" includes="*.jar"/>
<fileset dir="${google-play-services-libs-folder}" includes="*.jar"/>
<fileset dir="${external-libs-folder}" includes="*.jar"/>
<fileset dir="${native-libs-folder}" includes="**/*.jar"/>
<pathelement path="${main-out-classes}"/>
</classpath>
</javac>
</target>
<target name="dex" depends="compile">
<apply executable="${sdk.buildTools.dir}\dx.bat" failonerror="true" parallel="true">
<arg value="--dex" />
<arg value="--output=${intermediate-dex-location}" />
<arg path="${out-classes-location}" />
<fileset dir="${android-support-v7-appcompat-libs-folder}" includes="*.jar"/>
<fileset dir="${google-play-services-libs-folder}" includes="*.jar"/>
<fileset dir="${external-libs-folder}" includes="*.jar"/>
<fileset dir="${native-libs-folder}" includes="**/*.jar"/>
</apply>
</target>
and to Eclipse project. We can install and run our application by using Eclipse without any issues. But .apk which has been built by Ant we can just install. After try to open installed application we facing with exception in logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.android/com.my.android.Program}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:457) at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:279) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:244) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:114) at com.my.android.Program.onCreate(Program.java:180) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
in given line we are calling setContentView(splash); We checked that image file present into asserts, and Bitmap and ImageView correctly initialized.
ImageView splash = new ImageView(this);
splash.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
splash.setBackgroundColor(Color.BLACK);
String splashUri = getSplashScreenUri();
Bitmap splashBitmap = ImageUtils.getImage(splashUri);
splash.setImageBitmap(splashBitmap);
splash.setScaleType(ScaleType.FIT_XY);
DebugLog.log("splashUri is " + splashUri); //correct path
DebugLog.log("splashBitmap is null " + (null == splashBitmap)); //false
DebugLog.log("splashBitmap height " + splashBitmap.getHeight()); //correct height
setContentView(splash); //line 180
What did we miss for Ant script?
Upvotes: 0
Views: 490
Reputation: 13469
You may check on this blog and check if you missed something.
The Play library has to be included in your project.properties file like
android.library.reference.1=../google-play-services_lib
because it has resources that need to be included. However, Ant will fail your build because Google no longer provides abuild.xml
for the Play library. You can generate thebuild.xml
in the Play library by runningandroid update lib-project --path <playlib_path>
.
Usually, your error may be fixed by adding a call to getWindow().getDecorView()
prior to calling super.onCreate()
within the Activity's onCreate()
method. You can check it here and in this fixed bug reported before.
Upvotes: 0