Live ads from Admob is not showing - android

Yesterday I created an account on Admob and on my app the test ads working well but the live (real) ads not showing. When I added onFaildToLoad event it returns INTERNAL_ERROR. So is there any solutions? and is it important to upload the app on play store to get live ads?
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="208dp"
android:text="login" />
<EditText
android:id="#+id/editText"
android:layout_width="297dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="183dp"
android:ems="10"
android:inputType="textPassword" />
</RelativeLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-8140603259324677/7029410922">
</com.google.android.gms.ads.AdView>
</LinearLayout>
and this is my java code:
package com.example.moamen.webbrowser;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import static com.google.android.gms.ads.AdRequest.ERROR_CODE_INTERNAL_ERROR;
import static com.google.android.gms.ads.AdRequest.ERROR_CODE_INVALID_REQUEST;
import static com.google.android.gms.ads.AdRequest.ERROR_CODE_NETWORK_ERROR;
import static com.google.android.gms.ads.AdRequest.ERROR_CODE_NO_FILL;
public class LoginActivity extends AppCompatActivity {
Button mButton;
EditText mEditText;
private AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
try {
mAdView.loadAd(adRequest);
} catch (Exception e) {
e.printStackTrace();
}
mEditText = (EditText) findViewById(R.id.editText);
mButton = (Button) findViewById(R.id.button);
final String passA= "facebook";
final String passB = "moa";
// Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
MobileAds.initialize(this, "ca-app-pub-8140603259324677~4251010820");
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = mEditText.getText().toString().trim();
if (text.equals(passA)){
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
intent.putExtra("website","https://www.facebook.com/");
startActivity(intent);
}else if (text.equals(passB) ){
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
intent.putExtra("website","https://www.google.com/");
startActivity(intent);
}else {
Toast.makeText(LoginActivity.this, "Password is incorrect", Toast.LENGTH_SHORT).show();
}
}
});
mAdView.setAdListener(new AdListener(){
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
if (errorCode == ERROR_CODE_INTERNAL_ERROR){
Toast.makeText(LoginActivity.this,"ERROR_CODE_INTERNAL_ERROR",Toast.LENGTH_SHORT).show();
}else if (errorCode == ERROR_CODE_INVALID_REQUEST){
Toast.makeText(LoginActivity.this,"ERROR_CODE_INVALID_REQUEST",Toast.LENGTH_SHORT).show();
}else if (errorCode == ERROR_CODE_NETWORK_ERROR){
Toast.makeText(LoginActivity.this,"ERROR_CODE_NETWORK_ERROR",Toast.LENGTH_SHORT).show();
}else if (errorCode == ERROR_CODE_NO_FILL){
Toast.makeText(LoginActivity.this,"ERROR_CODE_NO_FILL",Toast.LENGTH_SHORT).show();
}
}
});
}
}
this is my gardle.build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.drshimaa.webbrowser"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0-rc02'
implementation 'com.google.android.gms:play-services-ads:15.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
the error
test ads is working well

If you are getting TestAds then your implementation is correct.
Change your package id and check

If you have recently created an AdUnit, then you have to wait for sometime to let the AdUnits get Activated...

Related

ViewBinding is not working in Second Screen[error: cannot find symbol import com.example.demoapp.databinding.DragAndDropBinding]

Basically I have a app with two Screen. ScreenOne and ScreenTwo. In the first Screen, i mean in MainActivity viewBinding is working fine. But on a perticular button click it will redirect to the second screen. Now there is the problem.
the error massage is -
error: cannot find symbol import com.example.demoapp.databinding.DragAndDropBinding;
But in the first Screen It's working fine.
MainActivity[FirstScreen]
//Working Fine
package com.example.demoapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.example.demoapp.databinding.ActivityMainBinding;
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
binding.dragOnly.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), DragActivity.class);
v.getContext().startActivity(intent);
}
});
}
}
ActivityMain.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:layout_centerVertical="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dragAndDrop"
android:text="Drag and Drop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag"
android:id="#+id/dragOnly"/>
</LinearLayout>
</RelativeLayout>
and the DragAndDropActivity[Second Screen]
//Showing error for import com.example.demoapp.databinding.DragAndDropBinding;
package com.example.demoapp;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.demoapp.databinding.ActivityMainBinding;
import com.example.demoapp.databinding.DragAndDropBinding; //Error
public class DragActivity extends AppCompatActivity {
TextView textView;
DragAndDropBinding binding;
float xPosition, yPosition, xPrevious, yPrevious;
#SuppressLint("ClickableViewAccessibility")
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drag_and_drop);
textView = findViewById(R.id.dragButton);
textView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int point = event.getActionMasked();
switch (point) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
xPrevious = event.getX();
yPrevious = event.getY();
return true;
case MotionEvent.ACTION_MOVE:
float dx = event.getX() - xPrevious;
float dy = event.getY() - yPrevious;
xPosition += dx;
yPosition += dy;
v.setX(xPosition - v.getWidth());
v.setY(yPosition - v.getHeight());
return true;
default:
return false;
}
}
});
}
}
DragAndDrop.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag Me any Where"
android:textSize="25sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="#+id/dragButton"
android:background="#056"
android:padding="8dp"
android:textColor="#FFF"/>
</RelativeLayout>
build.gradle[App]
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.demoapp"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
viewBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Android Studio version 3.6.1 and gradle plugin classpath 'com.android.tools.build:gradle:3.6.1'
I can see that you are actually not using ViewBinding in the second activity. You are just importing it generated class. Proguard obfuscates unused classes at runtime and it is thinking that you are not using your generated view binding class (which is right, you are just importing it.) so use it as you used in the first activity. It will work.

Unable to Sign in with google

I have to add sign in with google feature to my app. I have tried several tutorials but nothing works. Whenever I select an account from the list, that pop up gets closed and nothing happens. I don't know what is the problem since there is no errors showing on the logcat.
Login.java
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
public class Login extends AppCompatActivity {
GoogleSignInClient mGoogleSignInClient;
FirebaseAuth auth;
RelativeLayout googlesignin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
auth = FirebaseAuth.getInstance();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this,gso);
googlesignin = (RelativeLayout) findViewById(R.id.googlesignin);
googlesignin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 101);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
auth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = auth.getCurrentUser();
Intent i = new Intent(getApplicationContext(),Homewindow.class);
startActivity(i);
finish();
Toast.makeText(getApplicationContext(),"User Logged In Successfully",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(),"Login Failed",Toast.LENGTH_SHORT).show();
}
}
});
}
}
activity_login
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00BFFF"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<RelativeLayout
android:id="#+id/loginmain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/logincontents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/relativelayout_custom"
android:orientation="vertical"
android:padding="20dp">
<RelativeLayout
android:id="#+id/googlesignin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:orientation="horizontal"
android:background="#drawable/loginlayout">
<ImageView
android:id="#+id/googleicon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:src="#drawable/googleicon"/>
<TextView
android:id="#+id/googletext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/googleicon"
android:fontFamily="#font/averia_gruesa_libre"
android:text="Sign in with Google"
android:textColor="#db3236"
android:textSize="14dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/facebooksignin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_below="#id/googlesignin"
android:layout_marginTop="40dp"
android:background="#drawable/loginlayout">
<ImageView
android:id="#+id/facebookicon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:src="#drawable/facebookicon"/>
<TextView
android:id="#+id/facebooktext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:fontFamily="#font/averia_gruesa_libre"
android:layout_toRightOf="#id/facebookicon"
android:text="Sign in with Facebook"
android:textColor="#3b5998"
android:textSize="14dp"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:id="#+id/skipbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/facebooksignin"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:fontFamily="#font/averia_gruesa_libre"
android:paddingTop="5dp"
android:text="SKIP NOW >>"
android:textColor="#00BFFF"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/profileicon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:layout_above="#id/logincontents">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:src="#drawable/profile_icon"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Here I used onClickListener for the Relative layout containing googleicon and text.
build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "com.example.parethumukal"
minSdkVersion 18
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:18.1.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//noinspection GradleCompatible
implementation "com.google.android.material:material:1.0.0-rc01"
implementation 'com.github.bumptech.glide:glide:4.3.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
//noinspection GradleCompatible
def lifecycle_version = "2.0.0"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation files('libs\\YouTubeAndroidPlayerApi.jar')
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-database:18.0.0'
implementation 'com.google.firebase:firebase-storage:18.1.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
}
apply plugin: 'com.google.gms.google-services'
build.gradle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
logcat error
07-23 21:48:22.994 21934-21934/com.example.parethumukal E/MultiWindowProxy: getServiceInstance failed!
07-23 21:48:27.924 21934-21982/com.example.parethumukal E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb37a4d60
I don't know if any errors with my codes. Codes are taken from firebase site.
Try this
GoogleSignInOptions gso;
GoogleApiClient googleApiClient;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.firebase_web_client_id))
.requestEmail()
.build();
googleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.enableAutoManage(this, null)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}

Why i failed to register user using FirebaseAuth?

Im learning to use firebase to develop an app. But somehow i cannot register my user. I have look through everything and not sure what is the mistake. It kept prompting me "Failed to register" but im not sure what is the error. I have make sure that i already enabled email/password sign in method. And ive already make sure that the google play version is higher than firebase('com.google.firebase:firebase-auth:11.0.4'). Can someone please help me on this. Thank you
Updated: error message that i get
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "co.xtvt.xtvt"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
The xml:
<LinearLayout
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_margin="15dp"
android:id="#+id/editTextEmailRegister"
android:hint="Enter your email"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:layout_margin="15dp"
android:id="#+id/editTextPasswordRegister"
android:hint="Enter your password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_margin="15dp"
android:id="#+id/buttonRegister"
android:text="Register"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textViewLogin"
android:textAlignment="center"
android:text="Already registered? Login here"
android:layout_margin="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
The java:
public class Register extends AppCompatActivity implements View.OnClickListener{
private EditText editTextEmailRegister;
private EditText editTextPasswordRegister;
private TextView textViewLogin;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
editTextEmailRegister = (EditText) findViewById(R.id.editTextEmailRegister);
editTextPasswordRegister = (EditText) findViewById(R.id.editTextPasswordRegister);
findViewById(R.id.textViewLogin).setOnClickListener(this);
findViewById(R.id.buttonRegister).setOnClickListener(this);
mAuth = FirebaseAuth.getInstance();
}
public void RegisterUser(){
String email = editTextEmailRegister.getText().toString().trim();
String password = editTextPasswordRegister.getText().toString().trim();
if (email.isEmpty()){
editTextEmailRegister.setError("Email is required");
editTextEmailRegister.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
editTextEmailRegister.setError("Email is invalid");
editTextEmailRegister.requestFocus();
return;
}
if (password.isEmpty()){
editTextPasswordRegister.setError("Password is required");
editTextPasswordRegister.requestFocus();
return;
}
if (password.length() < 6){
editTextPasswordRegister.setError("Minimum length is 6");
editTextPasswordRegister.requestFocus();
return;
}
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
Toast.makeText(Register.this, "Registered succesfully", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(Register.this, "Failed to register", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.textViewLogin:
startActivity(new Intent(this, Login.class));
break;
case R.id.buttonRegister:
RegisterUser();
break;
}
}
}
Dont create using firebase tools in android studio. Create manually in firebase console and it works now.

Firebase Auth not working on emulator: class for com.google.firebase.auth not found

Im getting a "registration error" when I run my code and my online firebase users data is not getting updated. I checked my google play services version and updated gradle to compile with that version as I thought a later version would not work on my emulator, on my firebase project I have enabled "email/password" but my users database is not getting updated and I am throwing the "registration error" exception in my code, my password I am using is 10 characters long and contains one uppercase, some numbers and a hash just to be sure. Why is my database not getting updated, I suspected the google play services version but have downgraded this to the version my emulator is running and suspected my password but am using a more complex one but am still throwing a registration exception. I have added internet permissions on my manifest as I thought that could be a problem as well.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.swaziprocurement.mobileappie.MainActivity">
<LinearLayout
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:hint="Enter password"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Signup" />
</LinearLayout>
</RelativeLayout>
Main Activity:
package com.swaziprocurement.mobileappie;
import android.app.ProgressDialog;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class MainActivity extends AppCompatActivity {
private FirebaseAuth firebaseAuth;
private EditText editTextEmail;
private EditText editTextPassword;
private Button buttonSignup;
private ProgressDialog progressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
buttonSignup = (Button) findViewById(R.id.buttonSignup);
progressDialog = new ProgressDialog(this);
buttonSignup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
registerUser();
}
});
}
private void registerUser(){
//getting email and password from edit texts
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
//checking if email and passwords are empty
if(TextUtils.isEmpty(email)){
Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show();
return;
}
//if the email and password are not empty
//displaying a progress dialog
progressDialog.setMessage("Registering Please Wait...");
progressDialog.show();
//creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
//checking if success
if(task.isSuccessful()){
//display some message here
Toast.makeText(MainActivity.this,"Successfully registered",Toast.LENGTH_LONG).show();
}else{
//display some message here
Toast.makeText(MainActivity.this,"Registration Error", Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
});
}
}
Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle (Module App)
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.swaziprocurement.mobileappie"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.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:24.1.1'
compile 'com.google.firebase:firebase-auth:9.2.0'
compile 'com.google.android.gms:play-services-auth:9.2.0'
}
apply plugin: 'com.google.gms.google-services'
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swaziprocurement.mobileappie">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
logcat log:
09-25 12:00:18.324 14451-14613/com.swaziprocurement.mobileappie W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
09-25 12:00:18.332 14451-14613/com.swaziprocurement.mobileappie W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
09-25 12:00:28.457 14451-14613/com.swaziprocurement.mobileappie W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
I finally sorted it out, it was that I required to update my system images on my API build tools and update my system images on my emulator, that got it working

How to create Library Project in Android Studio with Resource [duplicate]

This question already has answers here:
Can I make an Android library which contains resource files?
(1 answer)
How to manually include external aar package using Gradle for Android
(26 answers)
Closed 7 years ago.
I am trying to create library project and used library code and resource to my other application, I can successfully get library activity or method which was not using any resource, but getting error when I try to use resource in activity or any method.
Here is my code.
package com.dhl.lib;
import android.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
public class AdditionActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initUI();
}
private void initUI() {
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
final EditText edtFirst = new EditText(this);
edtFirst.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
edtFirst.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
final EditText edtSecond = new EditText(this);
edtFirst.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
edtFirst.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
Button btn = new Button(this);
btn.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
btn.setText("Add");
btn.setBackground(getResources().getDrawable(R.mipmap.ic_launcher));
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(AdditionActivity.this, "==> " + (Integer.parseInt(edtFirst.getText().toString().trim()) + Integer.parseInt(edtSecond.getText().toString().trim())), Toast.LENGTH_SHORT).show();
}
});
linearLayout.addView(edtFirst);
linearLayout.addView(edtSecond);
linearLayout.addView(btn);
setContentView(linearLayout);
}
#Override
public void onClick(View v) {
}
}
Here another class which used resource
package com.dhl.lib;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
public class About {
public static void show(Activity activity, String aboutText,
String okButtonText) {
String versionNumber = "unknown";
Drawable icon = null;
String appName = "unknown";
View about;
TextView tvAbout;
try {
LayoutInflater inflater = activity.getLayoutInflater();
about = inflater.inflate(R.layout.about, null);
tvAbout = (TextView) about.findViewById(R.id.ca_tutortutor_aboutText);
} catch (InflateException e) {
about = tvAbout = new TextView(activity);
}
tvAbout.setText(Html.fromHtml(aboutText));
tvAbout.setMovementMethod(LinkMovementMethod.getInstance());
new AlertDialog.Builder(activity)
.setTitle(appName + " " + versionNumber)
.setIcon(icon)
.setPositiveButton(okButtonText, null)
.setView(about)
.show();
}
}
** XML Resource of About.xml **
<?xml version="1.0" encoding="utf-8"?>
<scrollview xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ca_tutortutor_aboutView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.dhl.lib.About">
<linearlayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="5dp">
<textview
android:id="#+id/ca_tutortutor_aboutText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"></textview>
</linearlayout>
</scrollview>
** Manifest of Lib Project **
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dhl.lib">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".AdditionActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
** app build.gradle **
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.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:23.1.1'
}
From that lib I can successfully get access of AdditionActivity on my Project but When I try to access About, getting error of java.lang.NoClassDefFoundError: Failed resolution of: Lcom/dhl/lib/R$layout;
Where I made mistake ? I can't found that point.
Here Is my Application app build.gradle which used library project
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.addtion.lib"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
provided files('libs/addition.jar')
}
** Application Main Activity Class **
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn_callAdd);
btn.setText("Call Addition Activity");
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, AdditionActivity.class));
}
});
((Button) findViewById(R.id.btn_callAlert)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
About.show(MainActivity.this, "Hello From Application", "Ok");
}
});
}
}

Categories

Resources