How can I define local environment variables in android studio? - android

I and a few colleagues are building an app and using git for version control.
Our app utilized the Google Maps Api, which generates unique api keys based on SHA1 certificates. To utilize maps, the api key must be referenced in the manifest as such
....
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api_key_goes_here"/>
</application>
We've each generated our own api keys based on builds of the app on our personal machines, but we'd like to have a properties file on each of our machines not checked into version control which stores our unique api key so we don't have to manually change the api key in the manifest each time we pull from the repository.
Is this possible? I know there are properties files in android studio but I haven't a clue how to use them, especially in this case.
EDIT:
Full manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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"
android:name=".Application">
<activity android:name="com.misfiremedia.parseexperiment.app.DispatchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.misfiremedia.parseexperiment.app.SignUpActivity">
</activity>
<activity
android:name="com.misfiremedia.parseexperiment.app.WelcomeActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name=".EmailLogInActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name="com.misfiremedia.parseexperiment.app.HomeActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name="com.misfiremedia.parseexperiment.app.home.PostLocationActivity"
android:configChanges="orientation|keyboardHidden"/>
<activity
android:name=".NewPostActivity"
android:configChanges="orientation|keyboardHidden"/>
<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="THIS_IS_THE_KEY_WE_NEEDED_TO_HAVE_DIFFERENT"/>
</application>

In Android there is a concept of buildTypes, so what you can do create three buildTypes or how many you are required in your team.
Like one, two and three as shown in picture below with three different manifests which all has different keys in each.
Now team memebers can choose their respective buildVariant and work, selected buildVariant doesnt have any affect when someone takes pull from git, it maintain the selection.

Related

why always app has been rejected and wasn't published due to a policy violation:

I am trying to upload apk on playstore from few days. but now days its showing list of core functionality in deceleration form like SMS and call log.
but in our apk there is no use of such permissions. I am using Internet and Fine Location permission, but its not listed there. there is compulsion that we require to select atleast one permission.therefore I am selecting Default SMS handler.
even I search through many tools there is no SMS and call log permission is used in whole source code.
As I found many answer on google that Make sure your SMS permission is given in manifest and give the pop up in user level.
but there is no permission in my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.demmyname.com">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!--<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />-->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.demmyname.com.Classes.Application"
android:allowBackup="true"
tools:replace="android:allowBackup"
android:icon="#mipmap/icon"
android:label="#string/app_name"
android:roundIcon="#mipmap/icon"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".Activities.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan" />
<activity android:name=".Activities.Activity_Login" />
<activity android:name=".Activities.Activity_SignUp" />
<activity android:name=".Activities.Activity_Forgot_Pwd" />
<activity android:name=".Activities.Activity_Profile" />
<activity android:name=".Activities.Activity_Change_Password" />
<service
android:name=".Services.AppLocationService"
android:enabled="true" />
<activity android:name=".Activities.Activity_Chnage_Location" />
<activity android:name=".Activities.Activity_Order_Delivary" />
<activity android:name=".Activities.Activity_Order_PichUp" />
<activity android:name=".Activities.Activityz_Hotel_Categories" />
<activity android:name=".Activities.Activity_Category_Items" />
<activity android:name=".Activities.Activity_Cart_List" />
<activity android:name=".Activities.Activity_Place_Order" />
<activity android:name=".Activities.Activity_MyOrders" />
<activity android:name=".Activities.Activity_About_Us" />
<activity android:name=".Activities.Activity_View_Offer"></activity>
<!--
<meta-data
android:name="io.fabric.ApiKey"
android:value="7aa3cad21d26b0edcfccea540b57016907999433"
/>
-->
<!-- <meta-data android:name="firebase_crash_collection_enabled" android:value="false" /> -->
<activity android:name=".Activities.Activity_PayUMoney"></activity>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
</manifest>
I am looking for solution how to skip declaration form or without selecting core functionality.
To make sure if any other libraries are using the violated permissions, do the following...
In your Android Studio, open the manifest file and observe that in the below of the page 2 (two) Tabs are there =>
Text
Merged Manifest
Click on the Merged Manifest tab. Then search for the
uses-permission
Check that if it contains any call log or sms permissions (or other violated permissions).
If you find any use of the violated permissions like that, add the following line in your manifest under the
manifest tag
<uses-permission android:name="android.permission.READ_SMS" tools:node="remove" />
And for each and every violated permission add another line like the above with the appropriate permission tag.
Then rebuild the project and check that your merged manifest does not contain any violated permissions. After the confirmation generate signed APK and update your application in the Google Play console. (For now, check the do not meet the Google privacy policies in the declaration form).
After a successful update and around after 24 hours, recheck that the form (in Play console) exist or not. There should not be any form after a successful APK update.
You may want to update your APK again after the form disappears for a clear update.

Android Wear: Watch face companion configuration activity issue when changing package name

I'm developing an Android Wear watch face along with its mobile companion configuration activity.
As a start I followed the documentation (https://developer.android.com/training/wearables/watch-faces/configuration.html#CompanionActivity) and used the available examples from Google (https://developer.android.com/samples/WatchFace/index.html), specifically the FitDistanceService.
If I use the actual code from the example it all works. The small gear icon - used to open the companion (phone) configuration activity - shows up in the Android Wear app on the phone and I can open the companion phone config activity by tapping on it.
But if I rename the package name from the default "com.example.android.wearable.watchface" to anything else (even to com.example.android.wearable.mycompany) the gear icon disappears from the Android Wear app on the phone and it becomes impossible to open the configuration activity.
I tried changing the package name in any possible way. I've tried using the Move, Copy, Rename functionalities in Android Studio (v. 2.2.3). I've tried to manually change the package name and all its occurrencies in all of the project files using Sublime Text, also renaming the related folders and changing any occurrence of the package name in the manifest.xml of wear and mobile apps.
After the renaming (moving, copying etc.) it all works perfectly. Not a warning, nothing. The watch face behaves as expected, but the gear icon simply disappears.
This is the MOBILE manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.wearable.watchface" >
<uses-sdk android:minSdkVersion="18"
android:targetSdkVersion="23" />
<!-- Permissions required by the wearable app -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Location permission used by FitDistanceWatchFaceService -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- All intent-filters for config actions must include the categories
com.google.android.wearable.watchface.category.COMPANION_CONFIGURATION and
android.intent.category.DEFAULT. -->
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- This activity is needed to allow the user to authorize Google Fit for the Fit Distance
WatchFace (required to view distance). -->
<activity
android:name=".ConfigActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.example.android.wearable.watchface.CONFIG_FIT_DISTANCE" />
<category android:name="com.google.android.wearable.watchface.category.COMPANION_CONFIGURATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
And this is the WEARABLE one:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.android.wearable.watchface"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="23"/>
<uses-feature android:name="android.hardware.type.watch"/>
<!-- Required to act as a custom watch face. -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- Required for complications to receive complication data and open the provider chooser. -->
<uses-permission android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA"/>
<!-- Location permission used by FitDistanceWatchFaceService -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BODY_SENSORS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<uses-library
android:name="com.google.android.wearable"
android:required="false"/>
<activity android:name="android.support.wearable.complications.ComplicationHelperActivity"/>
<!--
All intent-filters for config actions must include the categories
com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION
and android.intent.category.DEFAULT.
-->
<service
android:name=".FitDistanceWatchFaceService"
android:label="#string/fit_distance_name"
android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
android:resource="#drawable/preview_distance"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
android:resource="#drawable/preview_distance_circular"/>
<meta-data
android:name="com.google.android.wearable.watchface.companionConfigurationAction"
android:value="com.example.android.wearable.watchface.CONFIG_FIT_DISTANCE"/>
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService"/>
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
<activity
android:name=".FitDistanceWatchFacePermissionActivity"
android:label="#string/title_activity_fitdistance_watch_face_permission">
</activity>
<activity
android:name=".BodysensorsWatchFacePermissionActivity"
android:label="#string/title_activity_bodysensors_watch_face_permission">
</activity>
</application>
</manifest>
They both work perfectly, if you don't try to rename the package from "com.example.android.wearable.watchface" to something else.
Any clues? Of course I could go on with the "com.example.android.wearable.watchface" package name, but it seems implausible that it's not possible to change the package name.
Thank you!

I've set up Google Play Games Services in my game but nothing happens

I'm trying to enable Google Play Games in my Adobe Air game for Android. There are 2 apps a full and a demo one. But it looks like SignIn/SubmitScore/ReportAchievement codes are just being ignored, for both apps.
I'm using this ANE, but have also tried this and it's original fork. For all the result is the same. Code "ignored", nothing happens.
My project setup:
All the project was done, compiled and packaged in FlashDevelop. Platform is Air Mobile 14.0, SDK is Adobe Air 16.0. I use my own .p12 certificate for Android package, one for each App version.
I include the ANE on FlashDevelop the same way I included Game Center
ANE, for the same APP. The Game Center one is working, so I think
this one should also be fine.
I have added my com.google.android.gms.games.APP_ID to the xml, together with the additions required by the ANE.
In my code I do (and nothing happens, no callback is called, no signal is triggered, no sign in pop up screen, but my "trace" notification is shown, so the code is reached):
Games.initialize();
addListeners(); //Adding SignIn and SignOut callbacks
Games.promptUserToSignInOnStartup(true);
Games.start();
NotificationSystem.notifyLoading("Connecting to Google Play Games Service");
On Google's Developer Console:
Both apps are published for Alpha/Beta tests, there is no Production version yet.
I've set up Play Games Services, it is "Ready to test".
Both apps have been linked to it and authorized. I verified OAuth2.0 SHA1 fingerprint for both .p12 and they match.
This is my APK's AndroidManifest.xml, as I can't imagine the problem being on code side, or Google's console side.. I think it should be somewhere on ANE's config when packaging. So it might be here:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="air.mygame">
<application android:hardwareAccelerated="false" android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:configChanges="keyboardHidden|orientation|screenSize" android:label="#string/app_name" android:launchMode="singleTask" android:name=".AppEntry" android:screenOrientation="user" android:theme="#style/Theme.NoShadow" android:windowSoftInputMode="adjustResize|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="namespaceVersion" android:value="14.0"/>
<meta-data android:name="aspectRatio" android:value="portrait"/>
<meta-data android:name="autoOrients" android:value="true"/>
<meta-data android:name="fullScreen" android:value="true"/>
<meta-data android:name="uniqueappversionid" android:value="251bf45a-b5b6-49ae-bb1a-4337f47f8f34"/>
<meta-data android:name="initialcontent" android:value="mygame.swf"/>
<meta-data android:name="containsVideo" android:value="false"/>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="MY_APP_ID_ON_GOOGLE_PLAY_GAMES"/>
<meta-data android:name="com.google.android.gms.version" android:value="4242000"/>
<activity android:name="com.google.api.games.SignInActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
<activity android:name="com.google.api.games.StubActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
</manifest>
Ok! I found the error and it was indeed in the AndroidManifest.xml.
For anyone else struggling with this, the problem is that when working with Adobe Air we don't edit AndroidManifest.xml file directly, we edit application.xml using the manifestAdditions tag. And the needed additions were going to the wrong place.
My application.xml was like:
<android>
<manifestAdditions>
<![CDATA[<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<!-- GooglePlay Games Services -->
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="\ MY_GOOGLE_PLAY_GAMES_APP_ID" />
<meta-data android:name="com.google.android.gms.version" android:value="4242000" />
<activity android:name="com.google.api.games.SignInActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.google.api.games.StubActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
</manifest>]]>
</manifestAdditions>
</android>
Looking at Google's guide there could be no activity tag outside of the application tag on the final AndroidManifest.xml. Also, according to this, the meta-data tag should also be inside the application tag.
I just had to edit the application.xml so it looked like:
<android>
<manifestAdditions>
<![CDATA[<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<!-- GooglePlay Games Services -->
<application> <!-- This will be merged with application tag in the final manifest file -->
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="\ MY_GOOGLE_PLAY_GAMES_APP_ID" />
<meta-data android:name="com.google.android.gms.version" android:value="4242000" />
<activity android:name="com.google.api.games.SignInActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.google.api.games.StubActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
</application>
</manifest>]]>
</manifestAdditions>
</android>
To open your final AndroidManifest.xml, file for checking, you can use apktool.

Upload APK, google store - different package name

I am receiving this error whenever I try to upload my project to google play. However, I recently did a refactor - rename on my project package - "com.mike.myapplication1_0". I cleaned and rebuilt the file but I am still getting this error. I also updated the Manifest file as well...
Here is my manifest -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.solomichael.myappppppp" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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.solomichael.myappppppp.MyAndroidAppActivity"
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.solomichael.myappppppp.probability_act"
android:label="#string/title_activity_probability_act"
android:parentActivityName="com.solomichael.myappppppp.MyAndroidAppActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.michael.myandroidappactivity.MyAndroidAppActivity" />
</activity>
<activity
android:name="com.solomichael.myappppppp.showOldCards"
android:label="#string/title_activity_show_old_cards"
android:parentActivityName="com.solomichael.myappppppp.MyAndroidAppActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.michael.myandroidappactivity.MyAndroidAppActivity" />
</activity>
</application>
The package name should be unique (across google play store!) so it seems that someone else already used : com.example or com.mike.myapplication1_0 you'll have to choose another name!
Comment:
If you already have an app in the app-store and you change the package name and re-upload the apk - you lose all your current users (their app won't get updated!)
In the <meta-data> elements of two of your Activities you have attributes starting as follows...
android:value="com.example.
I'm not entirely sure why you have <meta-data> elements for those Activities but you either need to change the values to reflect your package name or simply delete the <meta-data> elements completely unless they're absolutely necessary.

All of a sudden the Maps in my Android Map stop working and all I see are a bunch of X's

I've deleted my debug key, generated a new one, gotten the new MD5 fingerprint and registered that with google and used the new API key in my layout XML, still broken. It was all working fine until a few days ago. Now all my maps are just a bunch of X's. Any ideas?
Do I need to sign my app for debug/development? All I have done so far is generate the fingerprint and used that to get an API key, am I missing a step perhaps?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.elon.ecs"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<service android:name="NewsEvents_Service"></service>
<activity android:name=".ECS"
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="ElonMap"></activity>
<activity android:name="NavigationActivity"></activity>
<activity android:name="NewsEvents"></activity>
<activity android:name="EditKeywords"></activity>
<activity android:name="FullNewsEvent"></activity>
<activity android:name="OnTheJob"></activity>
</application>
<uses-sdk android:minSdkVersion="4"/>
</manifest>
Have you checked that your permissions are still OK? You need the INTERNET permission to download the map tiles.
I've also been bitten, by putting the <uses-permission> tag after the <application> tag. This worked on all devices I tried except the SE Xperia X10 mini. Putting <uses-permission> first solved that one.
Also, make sure that you actually have an internet connection on your device (can you load web pages, for instance?)
You should also make sure that your application is being signed using the same keystore you used to generate your map key. If you're using eclipse to build, you'll find that keystore in the preferences, under Windows > Preferences > Android > Build.
There might be a problem on your mapView. are you trying to emulate satellite and street view?
Or your zoom level is too high.

Categories

Resources