Integrate ZXing in Android Studio - android
I'll start explaining all the steps I have done and in the end what is the problem.
Download ZXing-2.2 https://code.google.com/p/zxing/downloads/list
Extrac all in zxing-2.2.
Download and install Apache Ant http://www.youtube.com/watch?v=XJmndRfb1TU
With the use of Windows Commandline (Run->CMD) navigate to the extracted directory
In the commandline window - Type 'ant -f core/build.xml' press enter and let Apache work it's magic
At this moment is like Integrating the ZXing library directly into my Android application
But Wooops, "Buildfile: core\build.xml does not exists! Build failed. ok.
6. Importing ZXing - missing core/build.xml
Now yes, i have my core.jar.
Open Android Studio, File -> Import Project -> Select /android/ in /zxing-2.2/ -> Create project from existing sources -> Project name: andoid -> Source files for... all checked Next -> Libraries (cant do nothing) Next -> Modules (android checked) Next -> SDK 1.7 Next -> Finish
With Project Open -> Build -> Rebuild project
100 errors
19 warnings
File -> project Structure -> Libraries -> Add -> Java -> Select core.jar that i create before and OK -> Library 'core' will be added to the selected modules. (android) OK -> And OK in the Project Structure Dialog.
Build -> Rebuild Project
15 errors
20 warnings
All errors are error: constant expression required and
I see Error in Switch cases of ZXing project in android
I change all switchs for if elses.
0 errors
20 warnings
Ok, now continue:
File -> New project -> zxing_demo Next -> Next -> Blank Activity Next -> Finish
In new project -> File -> Import module -> Search and select /android/ OK -> Create module from existing sources Next -> Next -> Next -> Next -> Finish
Now I can see in the explorer /android/ /zging_demoProject/ and External Libraries
Now i change my code tu scan QR
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zxing_demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.zxing_demo.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:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:configChanges="orientation|keyboardHidden"
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter >
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
MainActivity.java
package com.example.zxing_demo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
Now test, Run -> Debug
And CRASH.
Logcat
08-31 02:58:28.085 20665-20665/com.example.zxing_demo E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zxing_demo/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
... 11 more
I can see in AndroidManifest.xml in this line
android:name="com.google.zxing.client.android.CaptureActivity"
"CaptureActivity" in red and the error say: Cannot resolve symbol 'CaptureActivity'
File -> Project Structure -> Modules -> zxing_demo -> Dependencies -> Add -> Module dependency -> android OK -> Apply and OK
Now CaptureActivity looks good
Debug again
08-31 03:06:58.513 21740-21740/com.example.zxing_demo E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zxing_demo/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
... 11 more
I think I will use the application and intents, but now I want do this work, if someone now whats happen tell me please.
I was integrating ZXING into an Android application and there were no good sources for the input all over, I will give you a hint on what worked for me - because it turned out to be very easy.
There is a real handy git repository that provides the zxing android library project as an AAR archive.
https://github.com/journeyapps/zxing-android-embedded
All you have to do is add this to your build.gradle
repositories {
jcenter()
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:3.0.2#aar'
implementation 'com.google.zxing:core:3.2.0'
}
and Gradle does all the magic to compile the code and makes it accessible in your app.
To start the Scanner afterwards, use this class/method:
From the Activity:
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
From a Fragment:
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.
There are several customizing options:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
They have a sample-project and are providing several integration examples:
AnyOrientationCaptureActivity
ContinuousCaptureActivity
CustomScannerActivity
ToolbarCaptureActivity
If you already visited the link you going to see that I just copy&pasted the code from the git README. If not, go there to get some more insight and code examples.
Anybody facing the same issues, follow the simple steps:
Import the project android from downloaded zxing-master zip file using option Import project (Eclipse ADT, Gradle, etc.) and add the dollowing 2 lines of codes in your app level build.gradle file and and you are ready to run.
So simple, yahh...
dependencies {
// https://mvnrepository.com/artifact/com.google.zxing/core
compile group: 'com.google.zxing', name: 'core', version: '3.2.1'
// https://mvnrepository.com/artifact/com.google.zxing/android-core
compile group: 'com.google.zxing', name: 'android-core', version: '3.2.0'
}
You can always find latest version core and android core from below links:
https://mvnrepository.com/artifact/com.google.zxing/core/3.2.1
https://mvnrepository.com/artifact/com.google.zxing/android-core/3.2.0
UPDATE (29.05.2019)
Add these dependencies instead:
dependencies {
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.google.zxing:android-core:3.3.0'
}
buttion.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new com.google.zxing.integration.android.IntentIntegrator(Fragment.this).initiateScan();
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Log.d("MainActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "Scanned");
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
}
}
dependencies {
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'com.google.zxing:core:3.2.1'
compile 'com.android.support:appcompat-v7:23.1.0'
}
From version 4.x, only Android SDK 24+ is supported by default, and androidx is required.
Add the following to your build.gradle file:
repositories {
jcenter()
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.1.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
}
android {
buildToolsVersion '28.0.3' // Older versions may give compile errors
}
Older SDK versions
For Android SDK versions < 24, you can downgrade zxing:core to 3.3.0 or earlier for Android 14+ support:
repositories {
jcenter()
}
dependencies {
implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.zxing:core:3.3.0'
}
android {
buildToolsVersion '28.0.3'
}
You'll also need this in your Android manifest:
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
Source : https://github.com/journeyapps/zxing-android-embedded
this tutorial help me to integrate to android studio:
http://wahidgazzah.olympe.in/integrating-zxing-in-your-android-app-as-standalone-scanner/
if down try THIS
just add to AndroidManifest.xml
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Hope this help!.
Related
Class Extending FirebaseMessagingService not working inside Android Library
I created an Android Library to implement FCM to use in my internal projects, where I implement a class to extend FirebaseMessagingService (.services.MyFirebaseMessagingService ) and another one to extend FirebaseInstanceIdService (.services.MyFirebaseInstanceIDService). I defined this in my AndroidManifest.xml inside the library as below: <!-- [START firebase_service] --> <service android:name=".services.MyFirebaseMessagingService" android:exported="true"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> <!-- [END firebase_service] --> <!-- [START firebase_iid_service] --> <service android:name=".services.MyFirebaseInstanceIDService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> </service> <!-- [END firebase_iid_service] --> When I included all the library source code as a module in my App, everything worked well, but when I included only the AAR generated, I received this error when I run my application: java.lang.RuntimeException: Unable to instantiate service com.example.lib.services.MyFirebaseMessagingService: java.lang.ClassNotFoundException: com.example.lib.services.MyFirebaseMessagingService at android.app.ActivityThread.handleCreateService(ActivityThread.java:2380) at android.app.ActivityThread.access$1600(ActivityThread.java:138) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4905) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: com.example.lib.services.MyFirebaseMessagingService at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) at java.lang.ClassLoader.loadClass(ClassLoader.java:501) at java.lang.ClassLoader.loadClass(ClassLoader.java:461) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2377) at android.app.ActivityThread.access$1600(ActivityThread.java:138) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4905) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) at dalvik.system.NativeStart.main(Native Method) The service com.example.lib.services.MyFirebaseInstanceIDService works correctly. What I need to do with AAR generated library to work?
For FCM follow this step : 1 - in main Build.gradle (not in app folder) add this line : buildscript { // ... dependencies { // ... classpath 'com.google.gms:google-services:3.0.0' } 2- in app/build.gradle add this line : apply plugin: 'com.android.application' android { // ... } dependencies { // ... compile 'com.google.firebase:firebase-core:9.8.0' compile 'com.google.firebase:firebase-messaging:9.8.0' // Getting a "Could not find" error? Make sure you have // the latest Google Repository in the Android SDK manager } // ADD THIS AT THE BOTTOM apply plugin: 'com.google.gms.google-services' Note : "Android Support Repository" in you SDk most be updated . Hope this help
click on Build - > Clean then install & run the app
API Version Incompatibilities
API Version Incompatibilities I have made an app using android studio, until now I have been testing it on a 'Nexus 5X (API 23) emulator'. However, today i started debugging the app on a 'Samsung Galaxy Tab 2 7.0 (API 18)' and the app will not even start. I know this is because of incompatibilities between the API's specifically something to do with the Theme i'm using. What i want to know is how i can fix this problem without changing the look of the app drastically. Log Cat Crash Log java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.********/com.***.********.MenuActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295) at android.app.ActivityThread.access$700(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:175) at android.app.ActivityThread.main(ActivityThread.java:5279) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:124) at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59) at com.***.*******.MenuActivity.onCreate(MenuActivity.java:47) at android.app.Activity.performCreate(Activity.java:5283) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295) at android.app.ActivityThread.access$700(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:175) at android.app.ActivityThread.main(ActivityThread.java:5279) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) Android Manifest <?xml version="1.0" encoding="utf-8"?> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:supportsRtl="true" android:theme="#style/AppTheme"> <activity android:name=".MenuActivity" android:label="#string/app_name" android:theme="#style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".About" /> <activity android:name=".SettingsActivity" /> <activity android:name=".********Activity" /> <activity android:name=".********Activity" /> <activity android:name=".VideoPlayerActivity" android:screenOrientation="landscape" /> <activity android:name=".*******Activity"></activity> </application> Gradle Build App File apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.***.*******" minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "2.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:22.2.1' compile 'com.android.support:design:22.2.1' } Note: The last two lines (the ones with compile...) are underlined in red and say 'This support library should not use a different version(22) than the compile SDK version(21).' Edit: If I change the Theme for the main activity to '#style/Theme.AppCompat.NoActionBar' the application will start however, the look of the application changes. Also, other activities that do not use the new theme work fine. Any Help is Appreciated.
No activity found to handle intent while using ant
I was trying to using ZXing as an external library for my project. I follow the step of this site It runs well on Eclipse, but, the APK created by Ant stops and show the following message in Logcat: FATAL EXCEPTION: main 09-23 16:54:44.816: E/AndroidRuntime(7570): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=remote.iWatchDVR (has extras) } 09-23 16:54:44.816: E/AndroidRuntime(7570): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580) 09-23 16:54:44.816: E/AndroidRuntime(7570): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431) Manifest: <activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden"> <intent-filter> <action android:name="com.google.zxing.client.android.SCAN"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> Intent: Button qrcode = (Button) findViewById(R.id.button_qrcode); qrcode.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View v) { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.setPackage(v.getContext().getResources().getString(R.string.rootPackName)); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, REQUEST_QRCODE); } }); I followed the steps explained in Class not found when using zxing, but the ant build failed after I copied zxing2.1.jar into /libs [dx] [dx] UNEXPECTED TOP-LEVEL EXCEPTION: [dx] com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/client/android/BeepManager$1; [dx] at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) [dx] at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) [dx] at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) I'm confused about configuring paths or settings for Ant.
The last build error shows that com.google.zxing.client.android referenced more than twice. Check on your build.grandle file on the compile and you will see two references of zxing package
Android ClassNotFoundException: Didn't find class on path
I can't find the solution of this error. Can you please give the permanent solution? I have no idea how to solve it. 01-04 11:06:42.302: E/AndroidRuntime(1906): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{e.gochat/e.gochat.gochat.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "e.gochat.gochat.MainActivity" on path: DexPathList[[zip file "/data/app/e.gochat-1.apk"],nativeLibraryDirectories=[/data/app-lib/e.gochat-1, /vendor/lib, /system/lib]] 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.access$700(ActivityThread.java:135) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.os.Handler.dispatchMessage(Handler.java:102) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.os.Looper.loop(Looper.java:137) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.main(ActivityThread.java:4998) 01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.reflect.Method.invokeNative(Native Method) 01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.reflect.Method.invoke(Method.java:515) 01-04 11:06:42.302: E/AndroidRuntime(1906): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 01-04 11:06:42.302: E/AndroidRuntime(1906): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 01-04 11:06:42.302: E/AndroidRuntime(1906): at dalvik.system.NativeStart.main(Native Method) 01-04 11:06:42.302: E/AndroidRuntime(1906): Caused by: java.lang.ClassNotFoundException: Didn't find class "e.gochat.gochat.MainActivity" on path: DexPathList[[zip file "/data/app/e.gochat-1.apk"],nativeLibraryDirectories=[/data/app-lib/e.gochat-1, /vendor/lib, /system/lib]] 01-04 11:06:42.302: E/AndroidRuntime(1906): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 01-04 11:06:42.302: E/AndroidRuntime(1906): at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.Instrumentation.newActivity(Instrumentation.java:1061) 01-04 11:06:42.302: E/AndroidRuntime(1906): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093) 01-04 11:06:42.302: E/AndroidRuntime(1906): ... 11 more 01-04 11:07:06.772: I/Process(1906): Sending signal. PID: 1906 SIG: 9 This is my app Manifest XML <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="e.gochat" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="18" /> <permission android:name="e.gochat.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="e.gochat.permission.C2D_MESSAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <application android:name="e.gochat.Common" android:allowBackup="true" android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:theme="#style/AppTheme" > <activity android:name="e.gochat.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="e.gochat.ChatActivity" /> <activity android:name="e.gochat.SettingsActivity" android:label="#string/title_activity_settings" /> <receiver android:name="e.gochat.client.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="e.gochat" /> </intent-filter> </receiver> <provider android:name="e.gochat.DataProvider" android:authorities="e.gochat.provider" android:exported="false"> </provider> </application> I'm not sure what's wrong here. I've added the .jar file in the java build path. And yet I'm getting this classnotfound exception. The app loads when I import the android.app.Application
I have solved this problem by disabling the instant run option of android studio. To disable Instant Run Goto File -> Settings -> Build,Execution, Deployment -> Instant Run -> Uncheck the checkbox for instant run
I don't know for sure what is your package name, but if it is e.gochat do this. Add package="e.gochat" to manifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="e.gochat" ..... ..... > On each activity declaration for android:name put a dot before activity name: <activity android:name=".MainActivity"> ............ </activity> <activity android:name=".ChatActivity"> EDIT After your edited I can see e.gochat is your package name. Now you only need to remove e.gochat from each activity/provider/receiver name as I said in second part of my answer. Android will add that for you.
Using Android Studio After upgrading to Android Stuido 0.8.2, I had this problem. I tried a lot of things, including Clean project Clean project (gradle clean) Invalidate Caches and Restart De-qualify the Activity Name in AndroidManifest.xml (.MyActivity) Nothing worked until I re-imported the entire project. File -> Close Project -> Import Project... -> Choose the same project -> OK This fixed it for me
Uninstalling the app in the device and running the project again fixed it for me.
The reason why this was affecting me was due to an incorrect path name in a layout file <android.support.v4.app.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.app.view.ViewPager> The correct absolute path of ViewPager is android.support.v4.view.ViewPager After correcting the path it worked. I did not have to prefix the activity name with a '.'.
For me, this was occurring on devices running < Android 5.0 because I didn't have multidex support enabled (this is, over 65k total methods incl. libs). Multidex is automatic and native on Android 5.0+ (specifically, devices using ART).
The problem was solved by removing MultiDexSupport from build.gradle file : defaultConfig { multiDexEnabled true // This line was causing above problem } Removing the MultiDexSupport solved the problem
This issue has multiple answers based on the different scenario. I was getting the same error when using a library(.aar) in my Android Studio project. The root cause in my case was that I missed to add a third party lib dependency in app's build.gradle file which was being used by the .aar file. e.g:- The library(.aar) was using 'com.squareup.okhttp3:okhttp:3.4.1'. So I had to add compile 'com.squareup.okhttp3:okhttp:3.4.1' in the app's build.gradle. Hope it helps someone.
ANDROID STUDIO In addittion to Kishor's answer: The error occured on my small project when I enabled multiDexEnabled = true in the gradle defaultconfig. Using the generated .apk file crashes on start of the app with the known error message. For me it was solved when I built the .apk file via gradle (right side of android studio) -> "yourapp" -> Tasks- > install -> installDebug Hope this helps someone with this strange error
I implemented a listener that was not available in the android version I was running yet and this led to the same error. Example MainActivity: // RecyclerView.OnScrollChangeListener is only available on API >= 23 public class MainActivity implements RecyclerView.OnScrollChangeListener { } Running this activity on a device with API < 23 will result in this error as well...
If you tried other solitions and none of them work. Sometimes this error happen because some library use Java 8 features. To solve the problem, configure Android Gradle Plugin to support Java 8 by adding the following code to your build.gradle file compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
For me the issue occurred as I wasn't including the kotlin-android and kotlin-android-extensions plugins in my :app modules build.gradle. E.g. plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-android-extensions' } Or if you're using the Kotlin DSL plugins { id("com.android.application") kotlin("android") kotlin("android.extensions") }
dependencies { implementation 'androidx.appcompat:appcompat:+' implementation 'androidx.constraintlayout:constraintlayout:+' } Remove this line from Gradle
while using Google Maps Android API v2 got error Signature not valid. Found:
I'm creating sample application to use Google Maps Android API v2. I tried on Samsung Galaxy Ace GT-S5830i, but instead of Map, I'm seeing And logcat is Signature not valid. Found: MIIDDTCCAfWgAwIBAgIEEhX+gTANBgkqhkiG9w0BAQsFADA3MQswCQYDVQQGEwJVUzEQMA4GA1UE ChMHQW5kcm9pZDEWMBQGA1UEAxMNQW5kcm9pZCBEZWJ1ZzAeFw0xMzAyMjUxMTEwNDRaFw00MzAy MTgxMTEwNDRaMDcxCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdBbmRyb2lkMRYwFAYDVQQDEw1BbmRy b2lkIERlYnVnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApqChoDnHsDfsxa7n2Kv9 2av0G0tm+kS1uP4T6fA8cO6jB3qB5EHFR6+5UO+k4laHW2WzOJbyhhtFE5eOTS4Zt5qo4FX/hsc/ Zi7dDX/Y13b+4qajhLoGYqVjM00eQc2qF58TTnbQ3lTERxaofYL2qI3j2KcVODFMksinL9lt3RTD V3MXy7KDLcuSvoVZxXn1L0O9rkTbZicmleK4wLDzI+lTpuXngAuQ4MBH1wEWwqMhJg6/J06t5axU ea2UVv7ZtYg8KPMEiQEApCbdAHtQsmqcsEQZtJAqFtj7KEQ7wTSgnpDRix4N5C9QlwUtKSlOCIlk ueUPVBypKf/SWIgF6QIDAQABoyEwHzAdBgNVHQ4EFgQURyMuspjlLaDj8LhEb5UyYqQgWQYwDQYJ KoZIhvcNAQELBQADggEBAA9IXLEAQTD+VEt9l8JQDEOFv8WqIdQisvmJCfJjN98faarvf6RRA+v3 HF2VFlZPaUu/HBeOH8MI7u+gNuRtZGYWn1eC/qfP0W31MQoNaN4ocsF+tL9INzpd89/u6Ya5Kove r0E0tpJFBgdtDPYcPBjQ6tYAqmhnmPIJftGHLNQbil4ocK/PkqgxGlwQN7WrCNjDewb0twz7hZBx Ig4OsnfdgPTYGlR+LyTzUd9/KyqaLHivRAI+y/xGDz6lOfGH7bDOPi/hDm0bkhC1y1J7L9+FiGWb dmi+Co9Jlf1f3vyTtD7kr3h0K0C3MsNWtybVqmVvgImoLt/lPbjNJahVrds= Google Play services signature invalid. Can't open keycharmap file Error loading keycharmap file Using default keymap My manifest code <?xml version="1.0" encoding="utf-8"?> <permission android:name="com.example.testmap.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.testmap.permission.MAPS_RECEIVE" /> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /> <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" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <permission android:name="com.example.testmap.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <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.maps.v2.API_KEY" android:value="AIzaSyDTsWrO0j24sbp4E5qhoHhd6nyOQM5lErc" /> <activity android:name="com.example.testmap.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> my xml file code <?xml version="1.0" encoding="utf-8"?> <fragment android:id="#+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="wrap_content" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" /> My activity code package com.example.testmap; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; public class MainActivity extends FragmentActivity { #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.final_main); GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); //map.getMinZoomLevel(); } } And clicking on ok button gives force close with Logcat FATAL EXCEPTION: main java.lang.NullPointerException at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374) at android.app.Activity.startActivityForResult(Activity.java:2827) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817) at android.app.Activity.startActivity(Activity.java:2933) at com.google.android.gms.internal.e$2.onClick(Unknown Source) at android.view.View.performClick(View.java:2485) at android.view.View$PerformClick.run(View.java:9080) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3687) 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:867) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) at dalvik.system.NativeStart.main(Native Method) Also when I UN-comment last line map.getMinZoomLevel(); , I get null pointer exception on the line.
Check if you have enabled offline work for gradle: Goto File > Settings > Gradle Deselect Offline Work if its checked. Then confirm if you have latest version of google services mentioned as dependencies in project level build.gradle: classpath 'com.google.gms:google-services:2.1.0' You can find latest version here: https://jcenter.bintray.com/com/android/tools/build/gradle/ Clean and build the project after gradle sync completes. ouThese steps solved a similar issue I'd with Google Maps and also solved the first error you mentioned Signature Not Valid If your device runs on Android M, you may want to verify your code for location access following this answer.
I was also getting same exception and I fixed it. Note: I am working on google analytics and was getting this exception. But my app was not crashing I was getting this in Logs. you can also try this solution. add this in project level gradle file. classpath 'com.google.gms:google-services:2.1.0' and this one for module level gradle file. compile 'com.google.android.gms:play-services:8.4.0' and move `below plugin at the end of file (at last line) of module level gradle file. apply plugin: 'com.google.gms.google-services'