How to integrate Vitamio in Android Studio? - android

I was trying to integrate Vitamio Bundle in my Android Studio project, and it didn't work here is my steps
I created a new Android Project "Blank Activity"
The i select File > New Module > import Existing Project Image
I got this list of import Summary Image
Now i went to file > Project Structure > app > dependencies and Added the Library
Then i got this error
i found out that if i remove the android:label="#string/vitamio_name" in the AndroidManifest.xml from the imported library the error will go away
i followed the instruction from here Vitamio Bundle
Activity
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
public class MyActivity extends Activity {
VideoView videoView;
private void test_2(){
String httpLiveUrl = "http://-------------.mp4";
videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
test_2();
}
}
Layout
<io.vov.vitamio.widget.VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="#+id/VideoView">
</io.vov.vitamio.widget.VideoView>
Manifest
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
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="io.vov.vitamio.activity.InitActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:launchMode="singleTop"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden" />
</application>
Error
09-12 13:48:27.020 1786-1786/com.stream.myapplication E/AndroidRuntime﹕ FATAL
EXCEPTION: main
Process: com.stream.myapplication, PID: 1786
java.lang.ExceptionInInitializerError
at io.vov.vitamio.MediaPlayer.<init>(MediaPlayer.java:96)
at io.vov.vitamio.MediaPlayer.<init>(MediaPlayer.java:78)
at io.vov.vitamio.widget.VideoView.openVideo(VideoView.java:221)
at io.vov.vitamio.widget.VideoView.access$2200(VideoView.java:62)
at io.vov.vitamio.widget.VideoView$9.surfaceCreated(VideoView.java:461)
at android.view.SurfaceView.updateWindow(SurfaceView.java:572)
at android.view.SurfaceView.access$000(SurfaceView.java:86)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1871)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at io.vov.utils.CPU.getFeature(CPU.java:101)
at io.vov.vitamio.Vitamio.<clinit>(Vitamio.java:129) ......
I'm not sure what does that error means... and is this is the right way for installing Vitamio in Android Studio?

Have you added this to your code?
public void onCreate(Bundle b) {
super.onCreate(b);
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
// your code
}
I am using vitamio library as well and the only difference I notice with your code is this. I have also removed the label from vitamio's AndroidManifest.xml and works fine for me.
Good luck!

After added Vitamio as module, Do not forget to add these lines in Vitamio build.gradle
jniLibs.srcDirs = ['libs']
Other vice app will not work.

Related

Google map V2 exception NoClassDeffFound

Believe me I have gone through at least a dozen of answers before posting as none of them is helping me out to resolve issue am facing, this google integration's are really sick.
So here is the problem statement "Display a map" thats it.
and here is what so far I have done.
Have imported google play services lib project in workspace(Using eclipse)
Have added this project as lib in my project
Added required permission and meta infos in manifiest file
Obtained proper apis keys and added into manifiest
Manifiest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" >
</permission>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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="AIzaSyCp8z8qSQdO_gFb92iru8Vyr7R7YNQglTo" />
<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>
</application>
</manifest>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="#+id/container"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.mapdemo.MainActivity" >
</RelativeLayout>
MainActivity.java
package com.example.mapdemo;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapFragment frag = MapFragment.newInstance();
getFragmentManager()
.beginTransaction()
.add(R.id.container, frag)
.commit();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
and here is the exception.
11-29 19:05:11.868: E/AndroidRuntime(19653): FATAL EXCEPTION: main
11-29 19:05:11.868: E/AndroidRuntime(19653): Process: com.example.mapdemo, PID: 19653
11-29 19:05:11.868: E/AndroidRuntime(19653): java.lang.NoClassDefFoundError: com.google.android.gms.maps.MapFragment
11-29 19:05:11.868: E/AndroidRuntime(19653): at com.example.mapdemo.MainActivity.onCreate(MainActivity.java:19)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.Activity.performCreate(Activity.java:5248)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.access$800(ActivityThread.java:139)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.os.Handler.dispatchMessage(Handler.java:102)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.os.Looper.loop(Looper.java:136)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.main(ActivityThread.java:5086)
11-29 19:05:11.868: E/AndroidRuntime(19653): at java.lang.reflect.Method.invokeNative(Native Method)
11-29 19:05:11.868: E/AndroidRuntime(19653): at java.lang.reflect.Method.invoke(Method.java:515)
11-29 19:05:11.868: E/AndroidRuntime(19653): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-29 19:05:11.868: E/AndroidRuntime(19653): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-29 19:05:11.868: E/AndroidRuntime(19653): at dalvik.system.NativeStart.main(Native Method)
Please help me out guys, am really loosing my control.
Snapshot of my eclipse project buildpath and android properties
Thanks,
Techfist.
'Use this code in xml for map view'
<com.google.android.gms.maps.MapView android:id="#+Id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
'Add in your activity'
MapView mapView =(MapView) findViewById(R.id.mapView);
Ha ha ha rofl,
So eventually, I tried lots of mixed and match, I even installed android studio and gave that system a chance, but after wasting 2 hours there I was not even able to figure out "how to launch my app",
eventually I came back to eclipse did all Comobs of build, clean, changing build paths etc. none of them worked out.
What did worked out was changing my workspace, and re building project with exactlysame code.

AdView - Missing adActivity with android:configChanges in AndroidManifest.xml

I just set up my app with the Google Play library method of adding adds (AdMob). When I run the emulator the add has the error message:
Missing adActivity with android:configChanges in AndroidManifest.xml
I located a fix at:
Missing adActivity with android:configChanges in AndroidManifest.xml
The fix stated to do the following:
"com.google.ads.AdActivity" is declared when using the admob sdk jar in the "libs" folder. >It seems you're using admob via the google play services library so change:
activity android:name="com.google.ads.AdActivity"
To
activity android:name="com.google.android.gms.ads.AdActivity"
Also make sure you add the meta-data tag:
I tried this and the CatLog said to change the meta tag back to:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
My LogCat:
02-23 14:30:27.091: E/AndroidRuntime(1278): FATAL EXCEPTION: main
02-23 14:30:27.091: E/AndroidRuntime(1278): Process: biz.midl.debtcalculator, PID: 1278
02-23 14:30:27.091: E/AndroidRuntime(1278): java.lang.RuntimeException: Unable to start activity ComponentInfo{biz.midl.debtcalculator/biz.midl.debtcalculator.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.os.Handler.dispatchMessage(Handler.java:102)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.os.Looper.loop(Looper.java:136)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-23 14:30:27.091: E/AndroidRuntime(1278): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278): at java.lang.reflect.Method.invoke(Method.java:515)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-23 14:30:27.091: E/AndroidRuntime(1278): at dalvik.system.NativeStart.main(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.internal.u.a(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.internal.ag.U(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.internal.ag.a(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at biz.midl.debtcalculator.MainActivity.onCreate(MainActivity.java:41)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.Activity.performCreate(Activity.java:5231)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-23 14:30:27.091: E/AndroidRuntime(1278): ... 11 more
Here is my .java:
import java.text.DecimalFormat;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class MainActivity extends Activity {
private AdView adView;
double interestRate;
double r, r1;
int nRemaining, nStarting, nDifference, originalBalance,
outstandingBalance, originalTerm;
double minPayment, additionalPayment, newPmt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adView = new AdView(this);
adView.setAdUnitId("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //edited out my unitID
adView.setAdSize(AdSize.BANNER);
LinearLayout layout = (LinearLayout) findViewById(R.id.ll);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Here is my Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
I also have my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="biz.midl.debtcalculator"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<activity
android:name="biz.midl.debtcalculator.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="biz.midl.debtcalculator.About"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.ABOUT" />
</intent-filter>
</activity>
</application>
</manifest>
You need to leave the meta-data tag as is:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Additionaly, you need to replace this tag:
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
With this (as suggested in the answer you linked):
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
Since you are using the Google Play Services and not the legacy AdMob SDK you need to replace the name of the activity class from com.google.ads.AdActivity to com.google.android.gms.ads.AdActivity
This may be part of the problem. It seems you are missing....
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
in you AndroidManifest.xml
Make sure you only have the Google Play Services library included and not both Google Play Services and Admob SDK.
It looks like the value of #integer/google_play_services_version is zero. Are the Google Play Services resources being included in your app?
if you are using unity you should use this.
<!-- Google Mobile Ads Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Removing the layout declaration and leaving the programmatic one worked. There were also some unrelated issues causing problems with Eclipse.
From update of play service to version 22 you can go without making above change , I am pasting the code for future reference here
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
in androidmanifest.xml file with having google play service as lib. project instead to use admobsdk.jar file
All you have to do is add this to your AndroidManifest.xml file:
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
it's appear to the screen missing activity with android configchanges in Android manifestxml

Google Maps api v2 not working and closes unexpectedly

Im almost just a beginner in android. I was trying to make a very simple app with google maps, ie just displaying maps. I followed the following link:
file:///C:/Android/Android%20Google%20Maps%20V2%20Tutorial.htm
But when I test it on my device it says it has stopped working and closes.
Here is my Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googleapi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<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="com.example.googleapi.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.maps.v2.API_KEY"
android:value="AIzaSyA5BsIL-3rppsOxQOuX4gBZT3c0cTHNbWc" />
</application>
</manifest>
Acyivity code is: (I tried extending FragementActivity but dosent work with it too.)
package com.example.googleapi;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
and XML code is( some part of it):
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
My logcat is:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.googleapi.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml
does not have the right value. Expected 4030500 but found 0.
You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.maps.internal.q.v(Unknown Source)
at com.google.android.gms.maps.internal.q.u(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
... 21 more
I have googled a lot about it and got some direct questions on it but no answer ?? .
It seems many have the same problem.Can anyone help with this problem. I want to develop an app but not able to proceed as Google mpas api is main part of it.
Your are missing a meta tag in the application tag of manifest
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You should use SupportMapFragment instead of MapFragment.
Change
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Change
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
TO
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
Whatever you have done is ok with older version of GooglePlayServices, but its apparently visible from your logcat that you are using GooglePlayServices 13 or higher so you need to add the meta data tag in your manifest just the way Raghunandan have answered.

java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable using actionbarsherlock

I need to use actionbarsherlock in my test project. Here is my activity:
public class MainActivity extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
}
and this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlocktest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.actionbarsherlocktest.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>
</application>
</manifest>
but when I run as an android application, it is said:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:998)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:915)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:849)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
at com.example.actionbarsherlocktest.MainActivity.onCreate(MainActivity.java:12)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
can someone help me?
This seems to be a problem in how you have your project and its libraries configured. The compiler is unable to find the auto generated R class for ABS which probably means it's just not being generated. You should try reimporting ABS into your project. This video on how to get started with the library might help: http://www.youtube.com/watch?v=4GJ6yY1lNNY.
Have you imported the libraries properly?
Well try this ! this might help you:
Libraries do not get added to APK anymore after upgrade to ADT 22

Android use Activity in Jar - NoClassDefFoundError

I am working on creating my own Android JAR file, this JAR will contain Activities which I need to call however I keep getting a NoClassDefFound error. It is only an issue with Activities contained in the JAR, any other objects called from the external JAR work fine.
Below are the steps I have taken when creating this JAR
I created a new library project called LibraryTest, and placed one Activity in it called LibraryActivity, which has a basic layout called librarymain.xml with some random text.
I have marked this project as a library, retrieved the JAR from the bin folder, I then created new project called TestAddLibrary. I added the JAR file to the lib folder, I then added the librarymain.xml from the LibraryTest project to the layout folder of the TestAddLibrary project.
I then added the the LibraryActivity to the manifest of the new project. Manifest looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testaddlibrary"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testaddlibrary.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>
<activity
android:name="com.example.librarytest.LibraryActivity"
>
</activity>
</application>
</manifest>
Then in the main activity of the new project, I have this
package com.example.testaddlibrary;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.example.librarytest.LibraryActivity;
public class MainActivity extends Activity
{
Button but;
Context context;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
but = (Button) findViewById(R.id.butNext);
but.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, LibraryActivity.class);
startActivity(i);
}
});
}
}
When I click the button to launch the LibraryActivity which is stored in the JAR file, I get this error
07-10 09:20:24.798: E/AndroidRuntime(28195): FATAL EXCEPTION: main
07-10 09:20:24.798: E/AndroidRuntime(28195): java.lang.NoClassDefFoundError: com.example.librarytest.R$layout 07-10
09:20:24.798: E/AndroidRuntime(28195): at com.example.librarytest.LibraryActivity.onCreate(LibraryActivity.java:20)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.Activity.performCreate(Activity.java:5104) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.access$600(ActivityThread.java:141) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.os.Handler.dispatchMessage(Handler.java:99) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.os.Looper.loop(Looper.java:137) 07-10 09:20:24.798:
E/AndroidRuntime(28195): at android.app.ActivityThread.main(ActivityThread.java:5041) 07-10
09:20:24.798: E/AndroidRuntime(28195): at java.lang.reflect.Method.invokeNative(Native Method) 07-10
09:20:24.798: E/AndroidRuntime(28195): at java.lang.reflect.Method.invoke(Method.java:511) 07-10 09:20:24.798:
E/AndroidRuntime(28195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-10 09:20:24.798: E/AndroidRuntime(28195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-10
09:20:24.798: E/AndroidRuntime(28195): at dalvik.system.NativeStart.main(Native Method)
I have read several questions on StackOverflow regarding this issue but nothing I have read has helped. I have the latest version of ADT Eclipse plugin, I have made sure that under Order and Export, I have ticked Android dependencies and Private Libraries.
Anyone have any idea what is causing this issue? Any help would be much appreciated!!
Edit: Forgot to mention other reason I am doing this is that I require my code to be hidden so I can share this out to other people without them seeing my code
You cannot package resources into jar files.
You can package pure java files that do not refer to any resources as jars.
In your case you need to reference the library project in your android project.
Library Projects
These projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse. Library projects cannot be installed onto a device, however, they are pulled into the .apk file at build time.
http://developer.android.com/tools/projects/index.html
To the question in the comment the closest resource could find
You cannot export a library project to a JAR file
A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.
How to create jar for Android Library Project

Categories

Resources