Can we implement multiple Content Providers to WhatsApp stickers app? - java

As my requirements are my app has the functionality of creating Custom Stickers and Stickers From Server a Single Content Provider causing issues, I tried a lot adding multiple Content Providers it's causing issues in Edit configuration
As seen below
This is how I am trying to add providers in manifest
<provider
android:name=".whats_app_based_code.provider.StickerContentProvider"
android:authorities="${contentProviderAuthority}"
android:enabled="true"
android:exported="true"
android:readPermission="com.whatsapp.sticker.READ">
</provider>
<provider
android:name=".whats_app_based_code.provider.StickerContentProviderServer"
android:authorities="${contentProviderAuthority}"
android:enabled="true"
android:exported="true"
android:readPermission="com.whatsapp.sticker.READ">
</provider>
App Level Gradle
android {
compileSdkVersion 30
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.numan.stickersapp"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
def contentProviderAuthority = applicationId + ".WhatsAppLicensedCode.StickerContentProvider"
def contentProviderAuthority2 =applicationId+".WhatsAppLicensedCode.StickerContentProviderServer"
// Creates a placeholder property to use in the manifest.
manifestPlaceholders = [contentProviderAuthority: "\"${contentProviderAuthority}\""]
manifestPlaceholders = [contentProviderAuthorityserver: "\"${contentProviderAuthority2}\""]
// Adds a new field for the authority to the BuildConfig class.
buildConfigField("String", "CONTENT_PROVIDER_AUTHORITY", "\"${contentProviderAuthority}\"")
buildConfigField("String","CONTENT_PROVIDER_AUTHORITY_SERVER","\"${contentProviderAuthority2}\"")
buildConfigField 'String', 'STICKERS_BASE_URL', "\"https://firebasestorage.googleapis.com/\""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

Finally, I did this part I am adding my approach to achieve this because Someone like me may want to add such functionality to their app:
What I actually did is:
I only added a single content provider in App Level Gradle and removed the other one
I added the second content provider through manifest and hardcoded the complete provider package like this:
<provider
android:name=".whats_app_based_code.provider.StickerContentProvider"
android:authorities="${contentProviderAuthority}"
android:enabled="true"
android:exported="true"
android:readPermission="com.whatsapp.sticker.READ">
</provider>
<provider
android:name=".whats_app_based_code.provider.StickerContentProviderServer"
android:authorities="com.numan.stickersapp.whats_app_based_code.provider.WhatsAppLicensedCode.StickerContentProviderServer"
android:enabled="true"
android:exported="true"
android:readPermission="com.whatsapp.sticker.READ">
</provider>

Related

I'm having trouble adding admob ads to the app

I want to add admob to my app, but when I add buildscript and allprojects to file project-level build.gradleI get a message all buildscript {} blocks must appear before any plugins {} blocks in the script
project-level build.gradle :
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
buildscript {
repositories {
google()
mavenCentral()
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
build.gradle/app :
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.test"
minSdk 28
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-
rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.google.android.gms:play-services-ads:21.2.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
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.example.test">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Test"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<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.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
</manifest>
Try This
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
remove buildscript {} and allprojects {} from project-level build.gradle,
latest version of Android Studio those code show in settings.gradle file, so no need to add those code inside project-level build.gradle

FirebaseApp initialization unsuccessful - error crashing app

In my main Activity right after i try to initialize the two references it crashes, only to find out the error "FirebaseApp initialization unsuccessful"
private StorageReference mStorageReference;
private DatabaseReference mDatabaseReference;
mStorageReference = FirebaseStorage.getInstance().getReference("uploads");
mDatabaseReference = FirebaseDatabase.getInstance().getReference("uploads");
there is some code between the private declaration and the code itself, but that is not relevant to this problem
The manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firebase10">
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The build.gradle(Project):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The build.gradle(app):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.firebase10"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-
optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api "com.google.android.gms:play-services-base:15.0.1"
api "com.google.android.gms:play-services-auth:16.0.0"
api "com.google.android.gms:play-services-identity:15.0.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "com.android.support:customtabs:28.0.0"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.gms:google-services:4.2.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'
}
I set up everything with Tools-Firebase, and i know that the code looks like it is glued together, since it is. I've been going through threads and just added things but nothing worked. If this matters, i am running the app on my phone, not emulator.
Is your google-json file is well setted ?
Also Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.
In build.gradle(Project) I Changed 'com.google.gms:google-services:4.1.0' To 'com.google.gms:google-services:4.2.0' and the problem is solved
This one here is non-sense, because that's a Gradle plugin:
dependencies {
implementation 'com.google.gms:google-services:4.2.0'
}
And this one belong to the bottom of the file:
apply plugin: 'com.google.gms.google-services'

Manifest merger failed with multiple errors, see logs on Android Studio

The error says that "Error:Execution failed for task ':app:processDebugManifest'. > "
I have tried many solutions on this website but still, the problem is not solved. Please help me
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="project.myapp">
<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"
tools:replace="android:appComponentFactory">
<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>
build.gradle(Module:app)
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 28
defaultConfig {
applicationId "project.myapp"
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
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:28.0.0'
implementation 'com.android.support:design:28.0.0'
// implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-database:11.0.4'
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.google.firebase:firebase-storage:11.0.4'
implementation 'com.firebaseui:firebase-ui-firestore:3.0.0'
implementation 'de.hdodenhof:circleimageview:2.0.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.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'
}
apply plugin: 'com.google.gms.google-services'
build.gradle(Project:myapp)
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
On Merged Manifest says that
Merging Errors: Error: tools:replace specified at line:5 for attribute
android:appComponentFactory, but no new value specified app main
manifest (this file), line 4 Error: Validation failed, exiting app
main manifest (this file)
For me, the solution was to just migrate to AndroidX.
On Android Studio, go to:
Refactor > Migrate to AndroidX
clean the project.
I.m delete this
tools:ignore="GoogleAppIndexingWarning",
tools:replace="android:appComponentFactory"
and fix this problem.good luck :)
Just remove the below line:
tools:replace="android:appComponentFactory"
And recompile and finally it works for me!
you should try this:
1:Remove tools:replace="android:appComponentFactory"
2:Provide new value for android:appComponentFactory" attribute
from:
Manifest merger failed, error on compiling
it worked for me!
solve my problem
Refactor > Migrate to AndroidX
In my case an error in Manifest file brought about this error at the time of generating apk although app was building flawlessly.
It was want of explicit 'exported' attribute in activity elements in Manifest file. after that apk too generated successfully .

Need solution for "Manifest merger failed with multiple errors"

I trying to user multiple module android project to work on my application and when I try to build the project. the project build fails with Manifest merge failures. I need help to resolve this issue.
I already tried changing the dependencies in Gradle files and tried rearranging them, searched other solutions in this and here as well, but none of them helped
my AndroidManifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.atomnest.chitfund">
<application
xmlns:tools="http://schemas.android.com/tools"
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"
tools:replace="android:appComponentFactory" />
</manifest>
since the project is not build successfully I'm not able to add any activity to the project
and my build.gradle File
apply plugin: 'com.android.application'
buildscript {
ext {
support_version = '1.0.2'
}
repositories {
mavenCentral()
}
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.atomnest.chitfund"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation "androidx.appcompat:appcompat:$support_version"
implementation 'com.jakewharton:butterknife:9.0.0-rc2'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc2'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.firebase:geofire-android:2.1.1'
implementation project(':utility')
implementation project(':library')
}
I am expecting to get the project build successfully and be able to launch the app in the emulator. pls help
here is the logcat image
If you are using androidx then you have to use all libraries compatible with androidx so you can use this code:-
In gradle.build (app) add this
compileSdkVersion 28
defaultConfig {
......
minSdkVersion 21
targetSdkVersion 28
......
}
And there are some implementations required to use androidx :-
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
And add these given two lines(below) to gradle.properties:-
android.useAndroidX=true
android.enableJetifier=true
Solution 1:
Suggestion: add 'tools:replace="android:appComponentFactory"' to
element at AndroidManifest.xml to override.
If you added the tools:replace="android:appComponentFactory" and still got trouble by fixing it, create a new project, copy-paste the codes and the same dependencies in there. After that, it should be fixed i hope.
If it didn't solve the issue, try adding these two:
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
In AndroidManifest.xml > <application tag of course.
Solution 2:
Add below two lines in gradle.properties
android.useAndroidX=true
android.enableJetifier=true
You can also follow below link:
https://developer.android.com/jetpack/androidx/migrate
Do let me know if you get any problem.
Actually I had the same issue.In my case it was butterknife. I changed the dependency into 8.8.1 and it works fine for me.

Cannot resolve symbol 'maps'

I imported mixare source code to Android Studio 3.1 but I get error message Cannot resolve symbol 'maps' in following lines:
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;
I saw this page but none of the answers were helpful. How can I fix this?
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '27.0.3'
defaultConfig {
applicationId 'org.mixare'
minSdkVersion 14
targetSdkVersion 24
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation project(':mixarelib')
implementation 'com.google.android.gms:play-services-maps:12.0.0'
}
AndroidManifest.xml:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
tools:ignore="AllowBackup"
tools:replace="android:label">
<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="(API KEY)" />
<uses-library android:name="com.google.android.maps" />
...
I solved this very easily.
Go to Settings | Appearance & Behavior | Android SDK and check 'Show Package Details'.
Select SDK version(I selected 7.0), check 'Google APIs' and install it. I don't know why the option doesn't exist in the version 7.1.1 and over.
And configure build.gradle like this:
compileSdkVersion 'Google Inc.:Google APIs:24'

Categories