I am trying to use some features of Google Play Services lib but I could not make it work. I have added the reference to the google play service libs to the manifest file (from Flash Builder)
<application android:enabled="true">
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:excludeFromRecents="false">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
In my ANE, I have added the reference to the source of google-play-services_lib, but when I tried to call the FREFunction to check the availability of Google Play Service
#Override
public FREObject call(FREContext context, FREObject[] args){
boolean result = false;
try{
Activity activitiy = context.getActivity();
activityContext = activitiy.getBaseContext();
result = isGooglePlayServiceExists();
}catch(IllegalStateException e){
Log.e(AneUtils.TAG, "Failed to get AIR current activity", e);
}
FREObject obj = null;
try{
obj = FREObject.newObject(result);
}catch(FREWrongThreadException e){
Log.e(AneUtils.TAG, "Failed to create FREObject from [" + result + "]");
}
return obj;
}
private boolean isGooglePlayServiceExists(Context activityContext){
int googlePlayServicesCheck = -1;
try{
googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activityContext);
}catch(Exception e){
Log.e(AneUtils.TAG, "Error getting googlePlayService state",e);
}
if(googlePlayServicesCheck == ConnectionResult.SUCCESS){
return true;
}
return false;
}
The ANE crashed at the line GooglePlayServicesUtil.isGooglePlayServicesAvailable(activityContext) so I really doubted the Google Play Service libs was not added.
Has anyone successfully imported the Google Play Serivce libs into Adobe AIR Android app?
Any advice or help will be appreciated. Thank you.
For anyone looking for the answer, hope this helps:
In order for us to use any Google Android library (or 3rd party Android library) in our ANE, you have to find out the real version number of your Android library then insert that number into your manifest file.
For example, instead of
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
We have to find out the real version number and your manifest data should be :
<meta-data android:name="com.google.android.gms.version"
android:value="4432145" />
In this case, the number 4432145 is the version number of the GooglePlayService library that we want to use. You can find out this number in the Resource of the Android library project.
In the future if you want to upgrade to use the latest version of GooglePlayService library, you have to rebuild your ANE file and correct the version number to the new version number of the library in your manifest file.
Related
I am developing an android application as part of a project, and am using Google places API to display places of interest based on location. I am using the PlacePicker Inentbuilder to accomplish this.
However, when the app is run, the place picker launches and then closes immediately (about 1-2 seconds).
I have already implemented the below suggestions (that I got from other answers):
I have generated the public API key for android applications, and am including this in the meta-data tag in the app manifest.
I have enabled the "Google Places API for android" API on the developers console.
I have included the latest play services version in dependencies in build.gradle.
I have included my code and the logcat below. Do let me know if I need to include anything else.
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sampath.project.project_v2" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/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.geo.api_key"
android:value="#string/google_api_key" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_api_key" />"
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login" >
</activity>
<activity
android:name=".PlacesSample"
android:label="#string/title_activity_places_sample" >
<meta-data
android:name="com.google.android.geo.api_key"
android:value="#string/google_api_key" />
</activity>
</application>
</manifest>
Build.gradle (app module - This is the only module)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.sampath.project.project_v2"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//compile fileTree(include: ['*.jar'], dir: 'libs')
//compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.google.android.gms:play-services:7.3.0'
}
PlacesSample - Activity that is using google places API:
package com.sampath.project.project_v2;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
public class PlacesSample extends AppCompatActivity {
TextView getLocation;
int PLACE_PICKER_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_places_sample);
getLocation = (TextView)findViewById(R.id.getLocTV);
getLocation.setClickable(true);
getLocation.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Intent intent;
try {
intent = builder.build(getApplicationContext());
startActivityForResult(intent, PLACE_PICKER_REQUEST);
System.out.println("start activity for result");
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_places_sample, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("onActivityResult");
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
}
Logcat:
05-05 23:38:30.593 21408-21408/com.sampath.project.project_v2 I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy#17e945c6 time:628772943
05-05 23:38:30.598 21408-21408/com.sampath.project.project_v2 I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy#17e945c6 time:628772948
05-05 23:38:31.517 21408-21408/com.sampath.project.project_v2 I/Timeline﹕ Timeline: Activity_launch_request id:com.sampath.project.project_v2 time:628773867
05-05 23:38:31.527 21408-21408/com.sampath.project.project_v2 W/ResourceType﹕ For resource 0x01030224, entry index(548) is beyond type entryCount(9)
05-05 23:38:31.527 21408-21408/com.sampath.project.project_v2 W/ResourceType﹕ For resource 0x01030224, entry index(548) is beyond type entryCount(9)
05-05 23:38:31.636 21408-21408/com.sampath.project.project_v2 I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy#2daadb0a time:628773986
05-05 23:38:33.869 21408-21408/com.sampath.project.project_v2 I/System.out﹕ start activity for result
05-05 23:38:34.227 21408-21408/com.sampath.project.project_v2 I/System.out﹕ onActivityResult
05-05 23:38:34.235 21408-21408/com.sampath.project.project_v2 I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy#2daadb0a time:628776586
Francois Wouts' solutions helped answer this. Thank you Francois...
I searched the logs with keyword 'Places' and found that Places API was indeed throwing an exception. It expected the com.google.android.geo.API_KEY within the <application> tags in the Manifest.xml.
I had changed to com.google.android.geo.API_KEY in the <activity> tag and not the one in the <application> tag.
Now changed to com.google.android.geo.API_KEY and removed the same lines from <activity> tag, and got it working. Feel like an idiot for not working this out by myself..
The meta-data tag should read android:name="com.google.android.geo.API_KEY"
It should be within the <application> tag in the Manifest.
Have you double checked that your API key is associated with your application (package name and SHA-1 fingerprint of your app's certificate) in the Developer Console?
You can find instructions at Signup and API Keys. Make sure to set it up for both your debug and your release certificates.
I hope that helps!
I was having the same issue. Make sure you enable Google Places API for Android and not just Places API in the Developer Console. "Places API for Android" will not show up under APIs & Auth/APIs because it isn’t a popular API (yet). You will have to search for it using the API search box.
In manifest file com.google.android.geo.api_key and com.google.android.maps.v2.API_KEY shouldnot be same.
go to https://console.developers.google.com/project
login and follow these steps to get key for placepicker places.
create or choose existing > use google apis > Google Places API for Android > enable > credentials in left menu > add credentials > api key > android key > create > copy key.
paste your key at manifest "com.google.android.geo.api_key"
Note : there is a limit of 1000 requests per day for google places api. after you have to pay money. Better to avoid PlacePicker.
In my case there was conflict of APIs. I have added google-service.json file which also had API key and I generated new key for Maps. So place picker was closing immediately.
Solution :
Use single API key which is in google-service.json file
Enable "Places SDK for Android" feature for your Google Cloud Platform project (with same name as in Firebase project , don't use different project. You will find same name project as you are using in Firebase)
Put SHA1 Application Restriction for android app (Recommended)
Check if you have placed following code in Application tag only
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="API_KEY" />
This issue made me crazy as well, there are so many issues regarding exactly this problem, but no one was helpful for me. At the end, I figured out that there are different Google Places APIs especially for Android. Consequently, the API-Key that I was using was simply for the non-Android version.
Generate your key using this link
https://developers.google.com/places/android-api/signup
May be you forgot to add your machine SHA key to the Google Maps Console. Faced same issue, Added my SHA Key to the console, it started working fine.
I filling out the Consent screen in APIs & Auth of the console and its working fine. Check the screen shot.
It was strange that it was a credentials problem for me. It works even without a warning in debugging mode but when i use released version of my app it just doesnt work (i have registered my release and debug sha1 keys) So i removed all restrictions and now its working.
Add compile 'com.google.android.gms:play-services-location:8.1.0' in gradle
I'll just drop this here, maybe it helps someone in the future.
For me, using the wrong Api key caused the crash, even though it worked fine in the past.
I had to use the second key (the one that is auto-created by Google services for Android) instead of the first one which i created.
In my case when I changed current API key with the one which is in google-service.json, it resolved the problem.
In google-services.json:
"api_key": [
{
"current_key": "PASTE THIS API KEY TO THE MANIFEST"
}
]
The PlacePicker is now officially deprecated.
I'm trying to complete the Udacity Advanced Android App Development course and running into the same issue.
https://developers.google.com/places/android-sdk/client-migration#place-picker-deprecation says that
The Place Picker was deprecated on January 29, 2019. It was turned off
on July 29, 2019, and is no longer available. Continued use will
result in an error message. The new SDK does not support the Place
Picker.
Cross-posting to https://github.com/googlemaps/android-places-demos/issues/2
The PlacePicker is now officially deprecated.
Try this library. Light weight and similar to placepicker with some additional features.
https://github.com/BilalSiddiqui/AddressPicker
In my case I had not provided google with my billing account details so the api was was disabled even after enabling it.
If this is also the case for you, add the billing account in the google cloud console and finally you will be able to do it.
I am using Netbeans 8.1 and the gluonhq jfxplugin 2.2.0.
I am trying to read a barcode, and created a new project (the standard hello world). I changed the button handler to call a function UpdateText() (below) which in turn calls the Charm Down Scan service.
When I run the app, and click on the button I get the following error in the Android Device Manager:
E/AndroidRuntime(3583): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.gluonhq.charm.down.android.scan.SCAN cat=[android.intent.category.DEFAULT] flg=0x4080000 }
This crash is happening on the scanservice.scan() line.
Button click handler code:
protected void UpdateText(Label label) {
ScanService scanService = PlatformFactory.getPlatform().getScanService();
StringProperty scannedString = scanService.scan();
scannedString.addListener((obs, ov, nv) -> System.out.println("Scanned String = " + nv));
}
I would greatly appreciate any help
You need to define the com.gluonhq.charm.down.android.scan.SCAN intent in your AndroidManifest.xml file. Add the following activity definition below your main activity definition:
<activity android:name="com.gluonhq.charm.down.android.scan.zxing.CaptureActivity"
android:screenOrientation="sensorLandscape"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.gluonhq.charm.down.android.scan.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
By default, the AndroidManifest.xml file is generated for you under the hood by the plugin. If you haven't setup a custom AndroidManifest.xml file yet, you can copy the one that the plugin generates. The default version is located in build/javafxports/tmp/android/AndroidManifest.xml. Just copy that one to a persistent location, i.e. src/android. Then update your build.gradle to tell the plugin that it should use the custom AndroidManifest.xml file instead of generating the default one:
jfxmobile {
android {
manifest = 'src/android/AndroidManifest.xml'
}
}
update:
You also need to add an extra dependency to the zxing core library as it seems it isn't included automatically when depending on the charm library alone:
dependencies {
androidRuntime 'com.google.zxing:core:3.2.1'
}
Furthermore, you'll have to add the CAMERA permission to your manifest as well:
<uses-permission android:name="android.permission.CAMERA"/>
Hey I know this was asked before, but none of the solutions seem to help. I'm using first time Facebook SDK in my application.
What I've tried:
I had tried most of the things found on Internet but did not get anything regarding this.
Here is my MainActivity.java:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
}
}
Here is My Activitymain.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.login.widget.LoginButton
android:id="#+id/connectWithFbButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text=" connect_with_facebook" />
</LinearLayout>
see my Logcat:
05-13 16:30:39.332: E/AndroidRuntime(10264): Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
Problem
While integrating Android SDK for a react-native project, I had finished the Android with React Native v0.30+ Project Configuration guide, and ran react-native run-android and then got this screen:
I learned that FacebookSdk.sdkInitialize is deprecated. see here
After some searching, I realized that the guide did not contain the steps to add the Facebook App ID for my app.
Solution
Open android/app/src/main/AndroidManifest.xml file and look in the <application> tag to confirm that this meta-data tag exists:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
Open android/app/src/main/res/values/strings.xml file and confirm that this there is a "facebook_app_id" string tag with your app id as the value:
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>
Run react-native run-android.
These are the steps that worked for me.
You have to use FacebookSdk.sdkInitialize(getApplicationContext()); before setContentView(R.layout.activity_main); as documentation states out. In case you need a complete facebook login example, check this one here.
You don't need to use FacebookSdk.sdkInitialize anymore. Check if your:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
is inside <application> tag.
For SDK v13.+ you must add Apple ID and Client Token.
Open the /app/res/values/strings.xml file in your app project and add:
<string name="facebook_app_id">1234</string>
<string name="facebook_client_token">56789</string>
Open the /app/manifests/AndroidManifest.xml file in your app project and add:
<application android:label="#string/app_name" ...>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="#string/facebook_client_token"/>
...
</application>
You can find your Client Token in your FB Developer account:
App > Dashboard > Settings > Advanced > Security > Client token.
There is a reason why sdkInitialize() is deprecated.
Go to your manifest file within the android folder and add following
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
After that append in your strings.xml file (res/values/strings.xml) the string entry:
<string name="facebook_app_id">APP_ID</string>
Close your Metro Builder and rebuild your Project using react-native run-android
Follow only 2 Step and your Facebook Sdk iw working in React Native
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>
Don't Need this b'coz Its Deprecated Now
FacebookSdk.sdkInitialize(getApplicationContext());
After checking the documentation I found that they are asking to initialize FacebookSdk in Application class onCreate() Method.
Snap code from Facebook doc:
public class MyApplication extends Application {
// Updated your class body:
#Override
public void onCreate() {
super.onCreate();
// Initialize the SDK before executing any other operations,
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
Seeing the responses listed in this question, the old way to initialize Facebook was:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Initialize the SDK before executing any other operations,
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
But we can get the message:
Facebook Sdk Has Not Been Initialized FacebookSdk.sdkInitialize()
FacebookSdk.sdkInitialize() now is deprecated.
Now (2021) Facebook initialization has changed, the Facebook initialization is automatically.
1 Add the following to the dependencies {} section of your build.gradle (module: app) file to compile the latest version of the Facebook SDK for Android:
implementation 'com.facebook.android:facebook-android-sdk:latest.release'
Add Your Facebook App ID and Client Token
Add your Facebook App ID and Client Token to your project's strings file and update your Android manifest:
1 Open your /app/res/values/strings.xml file.
2 Add a string element with the name attribute facebook_app_id and value as your Facebook App ID to the file. For example
<string name="facebook_app_id">Facebook App ID</string>
<string name="facebook_client_token">Facebook Client ID</string>
3 Open /app/manifests/AndroidManifest.xml
4 Add a uses-permission element to the manifest:
<uses-permission android:name="android.permission.INTERNET"/>
5 Add a meta-data element to the application element:
<application android:label="#string/app_name" ...>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="#string/facebook_client_token"/>
...
</application>
Use Initialise Callback Constructor like this:
Handler mHandler = new Handler();
FacebookSdk.InitializeCallback initializeCallback = new FacebookSdk.InitializeCallback() {
#Override
public void onInitialized() {
mHandler.post(new Runnable() {
#Override
public void run() {
//UI Code Here
}
});
}
};
//before setContentView()
FacebookSdk.sdkInitialize(getActivity().getApplicationContext(),initializeCallback);
If this helps anyone. For me I had to make this change
implementation 'com.facebook.android:facebook-login:latest.release' // for FB login
the above line of code must be added to the END of the dependencies object and not anywhere in between.
This is in android/app/build.gradle file
My app was crashing because the Privacy Policy url was not provided in "Settings/Basic" in https://developers.facebook.com/. (in fact it was provided but I had to "Save changes" again. Seems a bug from Facebook).
The app was working fine and the error message Facebook Sdk Has Not Been Initialized FacebookSdk.sdkInitialize()disappeared. Hope this help.
For me, this issue arose due to a package in my application called react-native-fbsdk.
Please check your package.json file for the same.
I removed the package using npm uninstall fbsdk and rebuilt by app and it worked perfectly.
Hope this solution works for you!
remove android:exported=true from AndroidManifest.xml and targetSdkVersion should be less than 31
I just finished setting up build variants with Gradle in Android Studio. What a blessing this will be for a typical demo/pro setup. I'm able to launch my 'demoDebug' app perfectly fine. When I switch to 'proDebug' and 'Run" with the same configuration it installs the pro app fine but crashes launching it:
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid
} Error type 3 Error: Activity class
{com.anthonymandra.rawdroidpro/com.anthonymandra.rawdroid.RawDroid}
does not exist.
If I then go to the dashboard I can launch the pro version and it works as expected. So the install works for the appropriate version; there's only something wrong in the launch (on pro).
build.gradle flavors:
productFlavors {
demo {
packageName "com.anthonymandra.rawdroid"
}
pro {
packageName "com.anthonymandra.rawdroidpro"
}
proAmazon {
packageName "com.anthonymandra.rawdroidpro"
}
}
Update
cleaned up extraneous info unrelated to the issue
When I decompiled the apk I confirmed that none of the gradle overrides were being implemented in the Android.manifest.
First you should have packagename in manner like (recommended approach not mandatory ):
youractualapplicationpackage.flavorname
But you can have packagname whatever you want for flavours like in your case:
productFlavors {
demo {
packageName "com.anthonymandra.rawdroiddemo"
}
pro {
packageName "com.anthonymandra.rawdroidpro"
}
proAmazon {
packageName "com.anthonymandra.rawdroidpro"
}
}
make sure com.anthonymandra.rawdroid is the application's java package inside your main/java directory.
Your AndroidManifest.xml should be like this(Only inside main directory):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anthonymandra.rawdroid" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".RawDroid"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:theme="#style/GalleryTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And it should be only in the main directory not anywhere else.
At compilation time gradle will do the necessary package name changes and will make the build.
Same worked fine in my machine and I was able to see two different apps in my device for two different flavors.
The issue was:
'manifestmerger.enabled=false'.
I disabled the function a while back because it caused issues with a library. In the meantime I forgot about it, but apparently the library merging also applies to the gradle merging. I suppose that makes some sense but they really need to allow for separation between gradle merging and library merging.
Thanks to #pyus13 for nonstop support till I came to the typical "Oh s---, are you kidding me..."
I am trying to Integrate ZXing QR Code into my android app without installing BarCode Scanner app, I have followed the steps as:
1) Firstly I have downloaded ZXing.zip file and extract it
2)open the ZXing project as an android existing project and then go to android folder and open the android folder and also include core.jar file into the ZXing project named CaptureActivity.
3)I have used the CaptureActivity project as a library in my project named 'QRCodeSample'.
(Problem in including CaptureActivity as a library)
4)My code is as below3:
public class QRCodeSampleActivity extends Activity {
Button b1;
static String contents;
public static final int REQUEST_CODE = 1;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
/*Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE",
"QR_CODE_MODE");
startActivityForResult(intent, 0);*/
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) {
contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.i("Barcode Result", contents);
Intent i1 = new Intent(QRCodeSampleActivity.this, webclass.class);
startActivity(i1);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("Barcode Result","Result canceled");
}
}
}
}
The manifest file is :
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<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="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>
<activity
android:label="#string/app_name"
android:name=".QRCodeSampleActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".webclass"></activity>
</application>
</manifest>
and its not adding library also
When I am trying to run my project,the error msg is:
Unable to instantiate activity ComponentInfo{com.qr.code/com.qr.code}: java.lang.ClassNotFoundException: com.qr.code in loader dalvik.system.PathClassLoader[/data/app/com.qr.code-1.apk]
Finally I got the answer,
As of ADT 14,the resource fields(such as R.id.decode) are no longer constants when defined in library projects
So in the ZXing library->android->com.google.zxing.client.android.CaptureActivityHandler.java and DecodeHandler.java
Replace both of these classes switch case statements with if-else,and then import this ZXing library into your project..
Rest of the coding of my own project is same...just the problem with the library classes as these are not updated as according to ADT 14..
Kanika
For all those Android Studio/Gradle users out there
Okay guys, as my task today was to integrate ZXING into an Android application and there were no good sources for input all over, I will give you a hint what made my be successful - cause it turned out to be very easy (on version 2.*).
There is a real handy git repository that provides the zxing android library project as an AAR archive.
https://github.com/embarkmobile/zxing-android-minimal
All you have to do is add this to your build.gradle
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
dependencies {
compile 'com.google.zxing:core:2.2'
compile 'com.embarkmobile:zxing-android-minimal:1.2.1#aar'
}
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:
IntentIntegrator.initiateScan(this); // `this` is the current Activity
If you already visited the link you gonna see that i just copy&pasted the code from there the git readme. If not go there to get some more insight and code examples!
Hope to be helpful for future readers. Peace :)
I had the same Problem and after hours struggling with it I finally managed to solve it like this. as Rubiraj is pointing
*Right Click on your project > Properties > Android > (under tab library) Add the Zxing project *
Assuming you were able to correctly create Zxing project as a Library as it is explained here :
http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/
You need to follow step as given by the link
http://www.androidaz.com/development/zxing-qr-reader-direct-integration
you can download core.jar from
http://repo1.maven.org/maven2/com/google/zxing/core/2.2/
The above is working for me, if your program still just put the core-2.2.jar in libs and clean your project
MaterialBarcodeScanner: Easy to use barcode reader for your Android Project (Uses Google Mobile Vision API).
Provide gradle dependency
compile 'com.edwardvanraak:MaterialBarcodeScanner:0.0.6-ALPHA'
Build a MaterialBarcodeScanner
private void startScan() {
/**
* Build a new MaterialBarcodeScanner
*/
final MaterialBarcodeScanner mBarcodeScanner
= new MaterialBarcodeScannerBuilder()
.withActivity(MainActivity.this)
.withEnableAutoFocus(true)
.withBleepEnabled(true)
.withBackfacingCamera()
.withText("Scanning...")
.withResultListener(new MaterialBarcodeScanner.OnResultListener() {
#Override
public void onResult(Barcode barcode) {
barcodeResult = barcode;
result.setText(barcode.rawValue);
}
})
.build();
mBarcodeScanner.startScan();
}
Hook it up to a button
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startScan();
}
});
Start scanning!
Step by step to setup zxing 3.2.1 in eclipse
Download zxing-master.zip from "https://github.com/zxing/zxing"
Unzip zxing-master.zip, Use eclipse to import "android" project in zxing-master
Download core-3.2.1.jar from "http://repo1.maven.org/maven2/com/google/zxing/core/3.2.1/"
Create "libs" folder in "android" project and paste cor-3.2.1.jar into the libs folder
Click on project: choose "properties" -> "Java Compiler" to change level to 1.7. Then click on "Android" change "Project build target" to android 4.4.2+, because using 1.7 requires compiling with Android 4.4
If "CameraConfigurationUtils.java" don't exist in "zxing-master/android/app/src/main/java/com/google/zxing/client/android/camera/". You can copy it from "zxing-master/android-core/src/main/java/com/google/zxing/client/android/camera/" and paste to your project.
Clean and build project. If your project show error about "switch - case", you should change them to "if - else".
Completed. Clean and build project. You can click on "Proprties" > "Android" > click on "Is Libraries" to use for your project
After importing Zxing as existing project, Properties > Java Buildpath > Check "is library" (check button) and then try to add Zxing as library.
Make sure webclass.class exist in your QRcodesampleActivity.java