GDK HelloWorld Service crash - android

I am building a HelloWorld-project called 'HelloGlass' using the GDK.
I have a HelloGlassActivity class, which works perfectly fine when launched and compiled. I then try adding another class, HelloGlassService, which extends android.app.Service and implements one abstract function. The moment I add this class, the project suddenly stops compiling with and throws the following error:
Android Dex: [HelloGlass] Unable to execute DX Android Dex:
[HelloGlass] java.nio.BufferOverflowException Android Dex:
[HelloGlass] at java.nio.Buffer.nextPutIndex(Buffer.java:499)
Now, Google and StackOverflow tell me that this error can be resolved by making sure that the AndroidManifest SDK version matches the one my project is dependent on. However, all my dependencies are JDK 1.6 and the GDK Sneak Peek.
As in Google's own Stopwatch example, my project does not include a project.properties file (I removed it after creating the default Android app template provided by IntelliJ and setting it to the GDK Sneak Peek SDK); and that's what my AndroidManifest.xml looks like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arik.HelloGlass"
android:versionCode="2"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:label="Hello Glass App" >
<activity
android:name="com.arik.HelloGlass.HelloGlassActivity"
android:label="Hello Glass Activity"
android:enabled="true" >
</activity>
</application>
</manifest>
As you can see, I did not even include that Service Class in the manifest, and yet it crashes. The Service class looks like this:
package com.arik.HelloGlass;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class HelloService extends Service{
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
And here are my module dependencies:
What am I doing wrong?

Related

AndroidTest does not use test application

Hi I faced that when I rewrite application in androidTest manifest file, it does not work. This is my AndroidManifest.xml file in androidTest folder:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.app"
android:installLocation="auto">
<application
tools:replace="android:name"
android:name=".app.ApplicationAndroidTest" />
</manifest>
This is part of original AndroidManifest.xml from main folder:
<application
android:name=".app.Application"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/Theme">
...
</application>
In fact I debugged it, and called getApplication() from breakpoint in activity under test, it returns .app.Application instead of ApplicationAndroidTest instance.
Do you have any ideas why android manifest file from androidTest is ignored?
As A workaround I used custom test runner class:
public class UiTestsRunner extends AndroidJUnitRunner {
#Override
#NonNull
public Application newApplication(#NonNull ClassLoader cl, #NonNull String className, #NonNull Context context)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
return Instrumentation.newApplication(ApplicationAndroidTest.class, context);
}
}
It seams ok for me. Hope it helps someone.
Changing application class at androidTest xml doesn't affect the app itself (tested app) but the additional android test apk that ships to the device for enabling tests. I'm not sure what is the exact meaning of application if any to android test apk.
anyhow busylee workaround is the available solution.
Important note: when defining custom instrumentation runner, it is required to run the tests with the custom runner, that can be done at Android Studio by editing run configuration of test run, under AndroidTests section with a test selected, there is 'Specific instrumentation runner (optional)' option.

Android external Service from a library (AAR, not Shared Service)

I am trying to create an Android Library containing a simple service. For example:
public class BasicService extends Service {
public BasicService() {
Log.d("I", "work");
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
I start the service the following way:
startService(new Intent(this, BasicService.class));
The service is compiled into an AAR file and after adding that to an application I get a ClassNotFoundException.
Caused by: java.lang.ClassNotFoundException: Didn't find class "nl.company.example.library.Services.BasicService" on path: DexPathList[[zip file "/data/app/nl.example.aartest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
I don't need to bind a service as the application does not have to communicate with the service. I also don't need an aidl interface as I don't want to share the service with other apps. I know I need to declare the service at the application side (not library) so I did that the following way:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.company.example.exampleApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<application
android:settings... >
<service
android:name="nl.company.example.library.Services.BasicService"
android:enabled="true"
android:exported="true" />
</application>
</manifest>
This is the manifest of my library:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.company.example.library" >
<application/>
</manifest>
I've done some research at Stackoverflow/Google and I wasn't able to find an answer to my problem.
Android service in library
Also tried different ways of starting the service (on action etc.) but no good so far.
All help is welcome and my apologies if I made an evil duplicate question.
The BaseService was implementing an interface from another library which was not packaged with the aar file. This caused the application to crash right after starting on a device, because it couldn't resolve the dependency.
public class BaseService implements OtherLibraryInterface {
...
}
Instead of throwing a ClassNotFoundException for the OtherLibraryInterface, Android would throw exactly that exception for the BaseService. Which is very confusing and lead us to believe that there is something wrong with the Service.
Adding the OtherLibrary dependency explicitly as a dependency to the main application solved this issue.

Unity project exported to android project exception (Multiple dex files define Lcom/qualcomm/QCARUnityPlayer/BuildConfig)

I exported the project from unity 4D to Android project but when i run it iget this error
Unable to execute dex: Multiple dex files define Lcom/qualcomm/QCARUnityPlayer/BuildConfig;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/qualcomm/QCARUnityPlayer/BuildConfig;
I did change the Project -> properties to include the Android 4.2.2 and Android Dependencies but i still not able to run it
The reason is the exported project (from Unity) has the same package name "com.qualcomm/QCARUnityPlayer" as one defined in QCARUnityPlayer.jar.
Please take the steps as I did it successfully.
1) Create your activity that extends QCARPlayerNativeActivity
package com.example.unitytest;
import android.os.Bundle;
import android.util.Log;
import com.qualcomm.QCARUnityPlayer.QCARPlayerNativeActivity;
public class MyUnityAR extends QCARPlayerNativeActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("Test", "MyUnityAR is running.");
}
}
2) Modify AndroidManifest.xml
< manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.unitytest" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal" >
...
< application android:icon="#drawable/app_icon" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
< activity android:name=".MyUnityAR" android:label="#string/app_name" android:screenOrientation="portrait" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
3) Clean and Build, then enjoy.
Reference: https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse

Android Gradle Build Variant Deploy

I just finished setting up build variants with Gradle in Android Studio. What a blessing this will be for a typical demo/pro setup. I'm able to launch my 'demoDebug' app perfectly fine. When I switch to 'proDebug' and 'Run" with the same configuration it installs the pro app fine but crashes launching it:
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid
} Error type 3 Error: Activity class
{com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid}
does not exist.
If I then go to the dashboard I can launch the pro version and it works as expected. So the install works for the appropriate version; there's only something wrong in the launch (on pro).
build.gradle flavors:
productFlavors {
demo {
packageName "com.anthonymandra.rawdroid"
}
pro {
packageName "com.anthonymandra.rawdroidpro"
}
proAmazon {
packageName "com.anthonymandra.rawdroidpro"
}
}
Update
cleaned up extraneous info unrelated to the issue
When I decompiled the apk I confirmed that none of the gradle overrides were being implemented in the Android.manifest.
First you should have packagename in manner like (recommended approach not mandatory ):
youractualapplicationpackage.flavorname
But you can have packagname whatever you want for flavours like in your case:
productFlavors {
demo {
packageName "com.anthonymandra.rawdroiddemo"
}
pro {
packageName "com.anthonymandra.rawdroidpro"
}
proAmazon {
packageName "com.anthonymandra.rawdroidpro"
}
}
make sure com.anthonymandra.rawdroid is the application's java package inside your main/java directory.
Your AndroidManifest.xml should be like this(Only inside main directory):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anthonymandra.rawdroid" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".RawDroid"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:theme="#style/GalleryTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And it should be only in the main directory not anywhere else.
At compilation time gradle will do the necessary package name changes and will make the build.
Same worked fine in my machine and I was able to see two different apps in my device for two different flavors.
The issue was:
'manifestmerger.enabled=false'.
I disabled the function a while back because it caused issues with a library. In the meantime I forgot about it, but apparently the library merging also applies to the gradle merging. I suppose that makes some sense but they really need to allow for separation between gradle merging and library merging.
Thanks to #pyus13 for nonstop support till I came to the typical "Oh s---, are you kidding me..."

MapActivity class not resolved to type even when project build target is Google

I'm trying to integrate Google maps into an app I am working on. I followed the set up guide and have already made sure the build target for project is one of the Google API targets. However, eclipse is still telling me that MapActivity is not a class.
Any idea what is going on?
Do you have an issue when compiling or when running the app?
If it's at compile time, did you import the class
import com.google.android.maps.MapActivity;
You'd also need to override the isRouteDisplayed() method
#Override
protected boolean isRouteDisplayed() {
return false;
}
As mentioned by Robert Estivill, more information is needed!
Maybe you are missing the Google Maps library declaration on your AndroidManifest.xml
<application ...
<uses-library android:name="com.google.android.maps" />
....
</application>

Categories

Resources