NoClassDefFoundError in FragmentMapActivity - java

I've seen this question asked often, but none of the proposed solutions seem to be working for me. I'm getting
E/AndroidRuntime(897): java.lang.NoClassDefFoundError: android.support.v4.app.FragmentMapActivity$4
when attempting to open a new FragmentMapActivity.
Code:
public class Maps extends FragmentMapActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps_simple);
//MapView for the lose :(
Toast.makeText(this, R.string.map_warning, Toast.LENGTH_LONG).show();
MapView mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
R.layout.maps_simple contains:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="<key removed for security>"
/>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="osmstudios.mappingapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/Theme.MapApp" android:hardwareAccelerated="true">
<uses-library android:name="com.google.android.maps" />
<activity android:label="#string/app_name" android:name=".AppMainActivity">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name="com.keyes.youtube.OpenYouTubePlayerActivity"></activity>
<activity android:label="#string/app_name" android:name=".Maps">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="osmstudios.mappingapp" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the inner code of the button press that opens the FragmentMapActivity intent:
Intent intent = new Intent(ctx, Maps.class);
startActivity(intent);
Finally, this is what my Libraries folder in the Java Build Path tool look like:
I've been really beating my head against a wall on this one. Any help would be appreciated.

This is bit late but I had the exact same issue and could at least resolve the "java.lang.NoClassDefFoundError:". In project property->java Build path -> Libraries, I had included android-support-v4.jar from android sdk path. This lib was available during compile time but not at run time. You need to copy this jar from sdk path to application libs location that way this lib is statically added to your app and could be found during run time. hope this helps. This solution I found after lots of search in StackOverFlow. Hers is the link. Trying to use DialogFragments via v4 compatability causes NoClassDefFoundErrors

It turns out the issue had to do with a change in Android versions.
More information and the fix can be found http://www.wiseappsllc.com/homepage/android-dev-tips

I had same problem, then i resolved it by checking the build path of the project. There i had two map jars. I deleted one in libraries, Now it is working fine. Just check it may work.

Related

Trying to use the Android "Parsing XML Data" code doesn´t work: "Error parsing XML"

I´ve got a problem with the code from this Android training-page: https://developer.android.com/training/basics/network-ops/xml.html
I downloaded the network usage.zip-file and didn´t change anything of the code. Unfortunately, it worked neither on my phone nor on my emulator.
After this, I googled the problem and found this thread here: Android Networkusage app,Error Parsing XML
I tried to solve the problem with the solution provided by this thread, but unfortunately, it didn´t work and still shows me the error: "Error parsing XML"
I am pretty sure the error is in the Manifest-file because I looked at the settings of my phone and the app doesn´t have any permissions to use the Wifi or mobile data.
This is my "Android manifest file", the rest of my code is exactly as the code downloaded from the reference guide:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.networkusage"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".NetworkActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="SettingsActivity" android:name=".SettingsActivity">
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
For anyone, who has the same issue: I found a way to make the app work. Actually, it worked without touching the manifest-file. However, in the "NetworkActivity.java"-file you need to change one line and paste in the URL directly (see below)
#Override
protected String doInBackground(String... urls) {
try {
return loadXmlFromNetwork("https://stackoverflow.com/feeds/tag?tagnames=android&sort=newest%22");
// *here instead of urls[0] you have to add the URL manually. I guess, it is not the most elegant solution, but it works ;)*
} catch (IOException e) {
return getResources().getString(R.string.connection_error);
} catch (XmlPullParserException e) {
return getResources().getString(R.string.xml_error);
}
}

adb shell dpm set-device-owner with Unity issue

I am trying to make a Unity app go into kiosk mode by using COSU (Corporate Owned Single Use) functionality.
My plan was to first get things working using just Android, so I followed the tutorial offered by Google Code Labs
After I got this working, my plan was to then figure out how to integrate this into my Unity project. I followed
this youtube video that showed how to make a plugin that can be called from Unity.
When I build my project, I try to execute the following command
adb shell dpm set-device-owner com.modalvr.unityplugin/.DeviceAdminReceiver
However, I keep getting the following error
Error: Unknown admin: ComponentInfo{com.modalvr.unityplugin/com.modalvr.unityplugin.DeviceAdminReceiver}
I wonder if Unity is not merging the AndroidManifest.xml files together correctly. Here is my AndroidManifest.xml file from plugin.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.modalvr.unityplugin">
<application android:allowBackup="true" android:label="#string/app_name" android:supportsRtl="true">
<receiver
android:name="com.modalvr.unityplugin.DeviceAdminReceiver"
android:description="#string/app_name"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin_receiver" />
<intent-filter>
<action android:name="android.intent.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.intent.action.PROFILE_PROVISIONING_COMPLETE"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
I copied it and the classes.jar file into Unity's Assets/Plugins/Android/libs folder
I am able to successfully call functions in my plugin, so the plugin appears to be set up correctly.
For reference, this is my C# code that calls into the plugin
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LockManager : MonoBehaviour {
#if UNITY_ANDROID
private AndroidJavaObject playerActivityContext = null;
#endif
public void SaveContext() {
#if UNITY_ANDROID
// First, obtain the current activity context
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
playerActivityContext = actClass.GetStatic<AndroidJavaObject>("currentActivity");
}
var plugin = new AndroidJavaClass("com.modalvr.unityplugin.PluginClass");
plugin.CallStatic<bool>("setContext", playerActivityContext);
#endif
}
public void LockButtonClicked() {
#if UNITY_ANDROID
SaveContext();
var plugin = new AndroidJavaClass("com.modalvr.unityplugin.PluginClass");
bool retVal = plugin.CallStatic<bool>("lock", 7);
#endif
}
public void UnlockButtonClicked() {
#if UNITY_ANDROID
SaveContext();
var plugin = new AndroidJavaClass("com.modalvr.unityplugin.PluginClass");
bool retVal = plugin.CallStatic<bool>("unlock", 7);
#endif
}
}
And this is the java class that defines those functions.
package com.modalvr.unityplugin;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
public class PluginClass {
private static Context context;
public static boolean setContext(Context ctx) {
context = ctx;
return true;
}
public static boolean lock(int number) {
Log.d("SOME TAG", "onReceive Lock");
Activity activity = (Activity) context;
activity.startLockTask();
return true;
}
public static boolean unlock(int number) {
Log.d("SOME TAG", "onReceive Unlock");
Activity activity = (Activity) context;
activity.stopLockTask();
return true;
}
}
It looks like Unity generates 2 XML files that it puts in Temp/StagingArea
AndroidManfist.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ModalVR.KioskPluginTest" xmlns:tools="http://schemas.android.com/tools" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="#style/UnityThemeSelector" android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false" android:isGame="true" android:banner="#drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="#string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
and AndroidManifest-main.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ModalVR.KioskPluginTest" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal" android:versionName="1.0" android:versionCode="1">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="#style/UnityThemeSelector" android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />
</manifest>
In neither of these files do I see the contents of my Android plugin AndroidManifest.xml I guess that is the issue. Do I need to do something to make the manifest files merge?
And for completeness, here is
DeviceAdminReceiver.java
package com.modalvr.unityplugin;
import android.content.ComponentName;
import android.content.Context;
/**
* Handles events related to the managed profile.
*/
public class DeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
private static final String TAG = "DeviceAdminReceiver";
/**
* #param context The context of the application.
* #return The component name of this component in the given context.
*/
public static ComponentName getComponentName(Context context) {
return new ComponentName(context.getApplicationContext(), DeviceAdminReceiver.class);
}
}
Thanks in advance for any help.
John Lawrie
Do I need to do something to make the manifest files merge?
Yes.
The manifest in Unity will automatically merge only if you compile the Java plugin as .aar package. If you build it as .jar file then you have to manually put the Manifest in the right folder in Unity so that Unity can merge it into your program during build.
You are currently building as .jar library so below is where to place the Manifest:
Put the AndroidManifest.xml file in your <ProjectName>Assets\Plugins\Android folder. Make sure to spell AndroidManifest and the folder names of where to put it correctly. That's it.

Imposible to develop a simple android app using Google Map API V2

I would like to use a Google Map in my current application. Before integrate it to my app, I created a test project to understand the functionalities.
I read this : https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api
and this :
http://developer.android.com/google/play-services/setup.html#
After a lot of problems with these errors :
didn't find class com.google.android.gms.maps.MapFragment
and
Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time)
When I run my project, Eclipse says "Launching Test:(99%)", then my computer temperature up to 100°C and Eclipse take 512% of my CPU ! So I'm obliged to force Eclipse to quit.
I spent a lot of time on stack overflow, rebuild, clean, add support library, delete project and recreate from the beginning etc.
Help me, I just want to create a basic app to test a GoogleMap !
My code :
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="***" />
</application>
</manifest>
Edit : I know now that the problem appears when I reference the google-play-services_lib to my project... Any ideas ?
public class YourActivity extends FragmentActivity {
GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity);
map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.iqamah_map)).getMap();
}
}
your xml :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/iqamah_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Add this in your Manifest
<uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
<uses-library android:name="com.google.android.maps" />
Even me having the same issue, then instead of getting API key from Google Map Android V2, i took the API key from Google Maps Embed API and included in the Manifest and solved my problem.
Proof:
1.API key i took for project
2.Used Key in Manifest.xml

My app gets the error "Unfortunately, App has stopped." every time I load it

I was initially trying to add a splash page to my app, and followed a tutorial on how to do so. However, now every time I load my app, it does to a white screen for a few seconds before saying "Unfortunately, [App] has stopped."
I was unable to find a way to copy LogCat, so here's an image of the errors which appear:
Also, here's my Manifest XML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bipbapapps.leagueclickerapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainClass"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.bipbapapps.leagueclicker.CLICKER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Deleting the splash Java and activity from the manifest does nothing to help now (and when I deleted it, I did revert MainClass to .LAUNCHER .
Can anyone make sense of the list, and/or help me run my app again?
From the logs, I found that you should
Call the requestFeature before setContentView();
The error says it you are calling setContentView() before requestFeature(). Don't do it.
LogCat should show you the problem. Click on all the error lines in the LogCat until you will be redirected to the problem.
I, myself, found that your problem could be at: Splash.java, line 19
Go check it out, hope it helps!

Intent resolved to different process when running Unit Test in Android

I have a small application that uses two activities. Both the activities inherit from MapActivity and display a map (com.google.android.maps).
Since the Android Google Map documentation says
Only one MapActivity is supported per
process. Multiple MapActivities
running simultaneously are likely to
interfere in unexpected and undesired
ways.
I modified my manifest to run the two activities in two different processes (I have removed some lines to make it short):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light">
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".Activity1"
android:process=".Activity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>Unit
</activity>
<activity
android:name=".Activity2"
android:process=".Activity2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
Now the application runs fine but I have problems when I what to run Unit Tests on both the Activities.
For example:
package com.example.myapp;
public class Activity1Test extends ActivityInstrumentationTestCase2<Activity1> {
Activity1 mActivity;
public Activity1Test() {
super("com.example.myapp.Activity1", Activity1.class);
}
#Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
setActivityIntent(new Intent());
mActivity = getActivity(); //An exception is thrown at this line
}
}
When I call the getActivity() method an exception is thrown:
java.lang.RuntimeException: Intent in process com.example.myapp resolved to different process .Activity1: Intent { flg=0x10000000 cmp=com.example.myapp/.Activity1 }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:377)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:100)
at com.example.myapp.Activity1Test.setUp(Activity1Test.java:28)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Is there a way to make the Unit Test to "resolve" the correct process?
Instrumentation runs all of your application components in the same process.

Categories

Resources