I have issue with build variants and FCM.
I have defined 3 variants: dev,qa,release
dev/qa have applicationIdSuffix '.dev'
release has no suffix
google-services.json file has both package names properly defined and I read that google-services plugin reads it automatically during build process.
When I launch the dev variant, everything works just fine. But after that if I switch to release variant and try to launch that the app just hangs giving following trace:
ANR in xxx
Reason: Broadcast of Intent { act=com.google.firebase.INSTANCE_ID_EVENT flg=0x14 cmp=xxx/com.google.firebase.iid.FirebaseInstanceIdInternalReceiver (has extras) }
Dev variant works always, but staging variant also hangs in the start.
Possible related issues:
Application not responding after adding Firebase
NOTE: I also tested debug variant with exact same config staging variant has and it worked. So Gradle do something different with debug variant because there are no problems with that.
Any ideas how to fix this? Is this because of Android Studio or maybe some wrong configuration in gradle? Colleague has never seen this issue when he builds the app.
I also tried to remove android studio and reinstall it, also removed the project and pulled the source again, but the error still happens with my laptop.
Thanks.
NOTE: I rebooted my laptop, and run clean assemble from the terminal, all of the variants now seem to work. I noticed that sometimes when building directly from Android studio it seems that the application kinda starts in parts and then it gets removed which then causes the FCM receiver to hang up because the app just got removed. Is this some configuration of Android studio?
CONCLUSION
Didn't find the actual reason of my Android Studio / Laptop / Gradle setup which caused this, but if you encounter the same issue. Try rebooting your computer, re-cloning app project might help, also building variant from command line with clean option can also help instead of building it with Android studio.
Make sure you have Implement both this services in your manifest file.
<service android:name="com.test.notification.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.test.notification.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
Try to put
apply plugin: com.google.gms.google-services
to the end of the build.gradle
and
compile com.google.firebase:firebase-messaging:x.x.x
top of dependencies
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.firebase:firebase-messaging:x.x.x'
}
apply plugin: 'com.google.gms.google-services'
Related
I tried upgrading Android Gradle Plugin from 4.2.2 to 7.0.1 using the upgrade assistant which is available in Android Studio at Tools > AGP Upgrade Assistant. The only change it made was to my project-level build.gradle file:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.1' // changed from 4.2.2 to 7.0.1
// ...
}
}
However, now when I run ./gradlew assemble assembleAndroidTest I get the following error:
/builds/locuslabs/android-team/locuslabs-android-sdk/app/src/main/AndroidManifest.xml:21: Error: MainActivity must extend android.app.Activity [Instantiatable]
android:name="com.locuslabs.appsdk.MainActivity"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Explanation for issues of type "Instantiatable":
Activities, services, broadcast receivers etc. registered in the manifest
file (or for custom views, in a layout file) must be "instantiatable" by
the system, which means that the class must be public, it must have an
empty public constructor, and if it's an inner class, it must be a static
inner class.
1 errors, 0 warnings
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
My project is multi-module, but I don't suspect that as the problem since it's complaining about the application module, not a library module.
I believe my <activity> tag is well formed in my AndroidManifest.xml for my application module:
<activity
android:name="com.locuslabs.appsdk.MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Furthermore, I don't think there is anything wrong with extending AppCompatActivity instead of android.app.Activity as I'm doing in my MainActivity.kt:
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
// ...
}
I'm concerned that Android Gradle Plugin 7.0.1 is not really ready for prime-time because the Android Gradle Plugin documentation still says classpath 'com.android.tools.build:gradle:4.2.0' instead of 7.0.1.
I saw that the Android Gradle Plugin 7.0.1 release notes mentioned some changes to linting but none of those changes seemed relevant to me.
I also skimmed through the Android Gradle Plugin source code to see if I could find the linting stage any identify any changes but it looked like a lot of work to find that code and do that analysis.
I searched for answers but all I could find were these two stackoverflow entries where the error was legitimate and the programmer just needed to change their code to ensure they were referencing an actual Activity:
Android Studio Error: Activity must extend android.app.activity
MainActivity cannot be cast to android.app.Activity
I also tried Android Gradle Plugin 7.0.0 but got the same error. Only Android Gradle Plugin 4.2.2 prevents the error.
Is this a bug in Android Gradle Plugin 7.0.1?
Update: could not disable Instantiatable
I tried to disable the Instantiatable lint error the following ways but none of them prevented the error.
First, I tried adding disable "Instantiatable" to my application-level build.gradle file:
android {
lintOptions {
disable "Instantiatable"
}
}
Second, I tried prepending #SdkSuppress("Instantiatable") to the class:
#SdkSuppress("Instantiatable")
class MainActivity : AppCompatActivity() {
// ...
}
Similarly, I tried #SuppressLint("Instantiatable") but that didn't work either.
the Android Gradle Plugin documentation still says classpath 'com.android.tools.build:gradle:4.2.0' instead of 7.0.1.
You need to read further down the page, to this and this. That table is only relevant for pre-7.0.0 versions.
Is this a bug in Android Gradle Plugin 7.0.1?
Quite possibly. Or, perhaps beyond, as the Instantiatable Lint check has a history of problems.
If your scenario does not match one of those three August 2021 bugs, and you are in position to provide a reproducible test case, file a fresh issue! Beyond that, if a clean-and-rebuild is not clearing up your problem, you might need to simply disable the Instantiatable Lint check for the time being by adding the following to all of your build.gradle files at the application or library level (i.e. all except your project-level build.gradle):
android {
lintOptions {
disable "Instantiatable"
}
}
Remember you can use the lint config xml file and add this "Instantiatable" rule as "ignored":
<lint>
[...]
<issue id="Instantiatable" severity="ignore" />
</lint>
In addition, you should configure lint plugin in your build.gradle to use the lint.xml file:
android {
[...]
lint {
lintConfig = file("$rootDir/config/lint.xml")
}
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pvijayalakshmi.previousversion">
<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>
</manifest>
grade file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.example.pvijayalakshmi.previousversion"
minSdkVersion 15
targetSdkVersion 26
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
}
I have developed an application. And I have installed it on my phone.
Now I have a requirement of adding one column to the my application. I have added one column to the database. I have made changes to the onUpgrade(). I have changed the database version from 1 to 2.
I have changed the version code and version name in gradle file.
I don't want to uninstall the app and re installing. I want to upgrade the app automatically.
Now I am trying to install my application(after adding column to database) in phone where previous application is also existed.
I need to upgrade my previously existed application. But I am facing issue here. The present app does not overwrite the previous application. Both applications packages names are same here.
How can I overcome this. I need the programmatic solution.
For example we have many apps like whatsapp. They have made changes to the app and releases. So, we directly update to the new version with out uninstalling our existing whatsapp. Like wise I am trying to do.
Any help would be appreciated.
When I am trying to install application, It is showing like this.
Go to your Developer Options in under mobile setting option
then, Enable these all are
USB Debugging
Install Via USB
Verify apps over USB
these all are should be enable mode(checked mode)
then you have to try..
If your existing i.e installed app in phone is signed APK then to overwrite the new APK on it means without uninstall old one run new APK , you have to install signed APK of new one in sdcard and after that install that. It will work.
you can check sure to uninstall once.
you can clear cache on your phone.after that switch off the phone you can try again install.
if the above not worked can you try creating signed APK file and install that once.
clear the project once again...
Android App Not Install. An existing package by the same name with a conflicting signature is already installed
This answer works for me thank you so much for stackoverflow.
You might want to disable instant run Android Studio Settings or Preferences-> Build,Execution,Deployment -> Instant Run.
clean and rebuild the project again
if you are using miui phone then Turn Off MIUI optimization
Settings --> Additional settings --> Developer options --> Turn Off MIUI optimization
I have integrated AppsFlyer SDK for analytics, it is tracking app installs but somehow when using uninstalls feature it crashes.
I have initialized SDK in MyApplication
AppsFlyerLib.getInstance().startTracking(this, Constants.APPS_FLYER_KEY);
I dont have GCM/FCM in my application so i have followed Android Uninstall Tracking
So i have written this code in my manifest
<service android:name="com.appsflyer.FirebaseInstanceIdListener">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
But it is not able to find FirebaseInstanceIdListener class
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.appsflyer.FirebaseInstanceIdListener"
Check the Android SDK installation steps. I followed this so I was not able to reproduce it.
So, I thought about possible cause, I tried to reproduce this error by simply not adding mavenCentral() in repositories object. And I faced the same error as you got.
Just to make sure if you have added below lines in your app.gradle before dependencies object:
repositories {
mavenCentral()
}
Adding to #Chintan-Soni's answer:
Our native Android SDK is distributed via MavenCentral repository, which replicates with the JCenter repository.
However, as we don't have control over this process, we instruct developers to add the MavenCentral repository to their project-level Gradle configuration file (build.gradle):
buildscript {
repositories {
mavenCentral()
}
}
And of course, Add the compile dependency with the latest version of the AppsFlyer SDK in the app-level build.gradle file:
dependencies {
compile 'com.appsflyer:af-android-sdk:4+#aar'
}
A local JAR file is another option to get the SDK.
You can find all the information required for integrating AppsFlyer SDK -
here.
Please submit any issues to support#appsflyer.com, so our support team could provide you with a quick and professional response.
When submitting an issue please specify your AppsFlyer sign-up (account) email , your app ID , reproducing steps, logs, code snippets and any additional information that could help.
I'm trying to setup a test project like is described in the Android Testing Blueprint but I receive the following NoClassDefFoundError:
java.lang.NoClassDefFoundError: android.test.mock.MockContentResolver
Android Studio resolves this correctly but when running I receive this error.
It's worth to note that I do not have an androidTest configuration on the app project, instead I only have a separate tests module with:
apply plugin: 'com.android.test'
I'm running tests like this:
./gradlew :tests:connectedAndroidTest
Test project to reproduce this issue can be found here:
https://github.com/vexdev/android-testing-templates/tree/master/AndroidTestingBlueprint
EDIT: Also asked on Android Development community
EDIT: Also created following android issue:
https://code.google.com/p/android/issues/detail?id=200182&thanks=200182&ts=1454489567
As #rds said, test package is not part of the framework on the device, therefore you need to include the package.
Seems like com.android.test plugin is not adding those classes, so you can fix it by adding
compile 'com.google.android:android-test:4.1.1.4'
in your dependencies for the module where you are applying the plugin.
Some android packages are not automatically linked, but you have to explicitly specify them using the <uses-library> tag. That is the case with the android.test package (see uses-library docs), like #rds mentioned.
Adding a compile dependency will work if you have minSdkVersion > =15, but will add a legacy Maven artifact that has been updated on the Aug 24, 2012 for the last time.
IMHO, it might be a better solution to add the following snippet to the manifest of the test module:
<application>
<uses-library android:name="android.test.runner" />
</application>
This will tell the system to include the android.test package as well, so the MockContentResolver will be found by the class loader.
Hope it helps.
The MockContentProvider is not part of the framework, it's only shipped in the SDK for test apks.
In your Android Studio project, you must store the source files for local unit tests under a specific source directory (src/test/java)
I am following this tutorial to make monkeytalk agent build so that i can record the event and write some test cases. I have also downloaded git project with is running but is not showing in monkey talk IDE and no events are recording.
I have also made my own project and follow all the steps from 1 to 9. I am testing it on real device so I skipped 10th step. The issue I am facing is that when I sync the project the gradle is building properly but when I am running the project it give me following error.
Error:Execution failed for task ':app:compileDebugJava'.
No such property: bootClasspath for class: com.android.build.gradle.AppPlugin
If anyone have any idea, your help is appreciated. Thanks!!!
After try lots of things i at last successfully integrated MonkeyTalk agent in my APK using Android Studio, here are some details steps that would help a lot.
Tip :
used gradle build version 1.0.0, although 1.2.3 is available but there are some issues with that version of gradle and the monkeytalk client agent apk.
if you are using google play services use 7.0.0 version
Steps :
For steps you can refer to this document
but here are few problems that I face when following this post, here are the following :
make libs folder in your app folder and put monkeytalk-agent-2.0.10.jar there, in your app build.gradle use this
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
....
}
no need of using
monkeytalkCompile fileTree(dir: 'monkey-libs', include: ['*.jar'])
this give me error when i am running the project
no need of writing
monkeytalk.initWith(buildTypes.debug)
monkeytalk {
applicationIdSuffix ".monkey"
}
just use this :
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
i think this will help, if anyone is facing problem please let me know. My build is successfully running on monkeytalk IDE
Instead of AspectJ plugin - com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.5' try to use https://github.com/Archinamon/GradleAspectJ-Android.
First add a maven repo link into your repositories block of module build file:
maven { url 'https://github.com/Archinamon/GradleAspectJ-Android/raw/master' }
Add the plugin to your buildscript's dependencies section:
classpath 'com.archinamon:AspectJ-gradle:1.0.15'
Apply the aspectj plugin:
apply plugin: 'com.archinamon.aspectj'
Now build your project and run.
Note: above changes are there only for step#3 and step#5. other steps will be same.