Trying to start Google Play Services Games example - java

I'm very new to Android studio, so this is probably a stupid question.
As of current I'm trying to follow this tutorial:
https://developers.google.com/games/services/android/quickstart
and got stuck at step 1 almost right off the bat. I downloaded the whole project as I'm trying to start and test "Typeanumber". Upon importing I went to "TypeaNumber" and changed the AndroidManifest.XML to a random domain. Quite obviously this didn't change anything. I still can't run the project and there're errors everywhere.
The XML looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pieps.testgame">
<application
android:supportsRtl="true"
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity
android:name="com.google.example.games.tanc.MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
In the source, where I find the classes, there're like 5 directories that all seem exceptionally redundant. In the classes the wrong package is displayed as well.
Am I suppose to change all packages throghout the entire project(if so the documentation fails pretty hard)? What am I suppose to do to get this working?

Related

Button does not show in emulator in Android Studio

I am fresh new to Android development. I just started but when I try to run a basic app with only one button, the button just simply does not show in emulator.
I looked everywhere, even saw similar question on stackOverflow from 2 years ago but answers do not suit my problem
Please tell me what part of code should I add here or anything else to get my app going. Thanks!
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I can't tell without showing your code. But I think you did not add constraints to your button.
Constraint Layout

How to fix the default activity not found problem?

my problem is related to Android Studio.Whenever I try to run my app I get an error that says default activity not found.Please help me out,it's really important.Thank you in advance!
Just in case,I've got 2 classes: the first one is MainActivity,the second one is CatRepository
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cats">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Try to replace <activity android:name=".ui.MainActivity"> by <activity android:name=".MainActivity">
Try putting full package name of your Activity.
You can try invalidating cache and restart.
File -> Invalidate Cache/Restart
Also after doing this, sync your project. : File-> Sync Project with Gradle Files

PLACES_API_KEY_INVALID shown but everything seems to be done right

My app uses the Google Places API to function however when I use the line placeLikelihoods.getStatus().getStatusMessage() , I get the message PLACES_API_KEY_INVALID. I've been googling for days and can't find a solution. When I go to https://console.developers.google.com/apis/credentials?project=myprojectdebug and click on my project, I am redirected to a page that shows my API key, the date I made it and my email used to make it.
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="censored b/c its got some private stuff in name">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<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-deta
android:name="com.google.android.geo.API_KEY"
android:value="My 39 character API key is here" />
</application>
What am I doing wrong? I feel like giving up but I also want to know what's wrong
EDIT: Found the problem however I can't fix it. I didn't use the proper keytool command shown here https://support.google.com/googleapi/answer/6158862 but when I run this command it gives me an error because my account name has a space between my first and last name thanks to me using a microsoft account.
Ok, i got your error. You misspell meta-data. Check your tag, you wrote 'meta-deta'
check this one in your manifest file i placed
android:name="com.google.android.maps.v2.API_KEY"
instead of this (place below one and check spelling)
android:name="com.google.android.geo.API_KEY"
in your AndroidManifest.xml file like
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/api_key"/>
1) Have you enable/activate google place api?
2) Did you keep switching your workstation? If you run your code using another pc (not the original one you use to generate api key), you need to request new API key because the debug key has changed.

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

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

All referenced layouts and Buttons in ALL my java files all have warnings on them and I dont know how to fix it

All layouts and button references mentioned in my java files all have warnings on them. The warning is always, button or layout cannot be resolved to a variable. I asked other developers for help on this and I was asked to remove the import android.R;. I was told it's not needed.
I did this and now all the R'S throughout my project have that same warning, I seemed to have traded one problem for another.
is there a way I can manually change the lines in the R.java file in gen/ because all layouts are in place in the layout folders and all buttons in the xml files have android:id:#+id/ I don't know what I have to do for Java to read its references so I can get past this hump.
Manifest
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ZohanActivity"
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=".MacAttack"
android:label="#string/app_name" >
</activity>
<activity
android:name=".ConsultationReq"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
First of all are you sure it's a warning? or is it an error?
Secondly, never modify the R file, because it is generated automatically. So all your modifications will be lost.
I would have to guess it's an error and not a warning. Here is what I propose to you:
Clean your project and rebuild
right-click the error, click on quick fix and choose "import package_name.R"

Categories

Resources