All Activities and layouts got corrupted in Android Studio - android

I am working on a projects since 3 months. Today most of my activities and xml files got corrupted. I have tried deleting workspace.iml file but it remains same.Local History in VCS is also empty. Is there any way to recover my code or solve this issue.
Note These files are same as previous if I open then in Notepad app/scrc/main/activity.java, but showing different in Android studio
Here what my code looks like now
<component name="libraryTable"> <library name="Gradle: com.google.firebase:firebase-measurement-connector-impl-17.0.3">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/firebase-measurement-connector-impl-17.0.3.aar/fb2536827bf92d82ab72080a9863eb78/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/firebase-measurement-connector-impl-17.0.3.aar/fb2536827bf92d82ab72080a9863eb78/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
gradle file:
apply plugin: 'com.android.application'apply plugin: 'com.google.gms.google-services'android {
compileSdkVersion 28
defaultConfig {
applicationId "com.apkfeast.class11walkthrogh"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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.constraint:constraint-layout:1.1.3'
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'
implementation 'com.android.support:design:28.0.0'
implementation 'com.github.chrisbanes:PhotoView:2.1.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.firebaseui:firebase-ui-database:4.2.1'
implementation 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.github.bumptech.glide:annotations:4.8.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.android.gms:play-services-ads:17.1.1'
implementation 'com.android.support:multidex:1.0.3'}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.apkfeast.class11walkthrogh"
android:screenOrientation="portrait" >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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"
android:fullBackupContent="true">
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<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"/>
<activity android:name=".Hyderabad" />
<activity android:name=".Mirpurkhas" />
<activity android:name=".SelectBoard" />
<activity android:name=".Quiz" />
<activity android:name=".Notes" />
<activity android:name=".fedral" />
<activity android:name=".sukkur" />
<activity android:name=".larkana" />
<activity android:name=".aghakhan" />
<activity android:name=".sarghoda" />
<activity android:name=".Rawalpindi" />
<activity android:name=".Faisalabad" />
<activity android:name=".Multan" />
<activity android:name=".Gujranwala" />
<activity android:name=".lahore" />
<activity android:name=".karachi" />
<activity android:name=".sahiwal" />
<activity android:name=".dgkhan" />
<activity android:name=".peshawar" />
<activity android:name=".bahawalpur" />
<activity android:name=".balochistan" />
<activity android:name=".hydchem" />
<activity android:name=".hydphy" />
<activity android:name=".hydbio" />
<activity android:name=".hydeng" />
<activity android:name=".hydisl" />
<activity android:name=".hydurd" />
<activity android:name=".hydmat" />
<activity android:name=".hydpak" />
<activity android:name=".hydviewdown" />
<activity android:name=".mpkVD" />
<activity android:name=".fedVD" />
<activity android:name=".sukVD" />
<activity android:name=".larVD" />
<activity android:name=".sarVD" />
<activity android:name=".rawVD" />
<activity android:name=".faiVD" />
<activity android:name=".mulVD" />
<activity android:name=".gujVD" />
<activity android:name=".lahVD" />
<activity android:name=".khiVD" />
<activity android:name=".sahVD" />
<activity android:name=".dgkVD" />
<activity android:name=".pesVD" />
<activity android:name=".bahVD" />
<activity android:name=".balVD" />
<activity android:name=".result" />
<activity android:name=".bioquiz" />
<activity android:name=".chemquiz" />
<activity android:name=".phyquiz" />
<activity android:name=".full" />
</application>
</manifest>
Solved
I have fixed it by deleting all the files in C:\Users\cc.AndroidStudio3.2\system\caches.

I also had the same problem this morning.
I thought this was due to migrating to AndroidX but
It was wrong. It may occur due to improper indexing and building for e.g. the indexing is force stopped. or due to some IDE issues.
The isuue resolved by deleting gradle and .idea folder in project
and clearing cache of Android Studio IDE by D:\Users\ABCD.AndroidStudio3.2\system\caches.
And issue was resolved.
Note:- Please take Project Backups Daily.

Solution for Android studio Arctic Fox and Higher Versions
Steps
Exit Android Studio
Delete caches folder from
C:\Users\{username}\AppData\Local\Google\AndroidStudio2020.3 // For Arctic Fox
Open Android Studio and your code has being Perfect
Check your Android studio version and Target that version folder at below location
C:\Users\{username}\AppData\Local\Google
Note : AppData folder is Hidden in Windows

Erasing the cache of the Android studio will resolve the problem, for that you have to go to:
C:\Users\user\.AndroidStudio3.5\system\caches
(On windows)
and on Mac:
~/.AndroidStudio3.5/system/caches
Delete all the files there and restart the Android studio.

I solved that by
Close project you are working on
//This enables deleting all cache files
Close android studio
navigate to .AndroidStudio folder and then sytem then cache
delete the cache
Go to your project folder delete delete gradle and .idea folder
delete app.iml file too
import project dont open as exixting.
Boom you done.

Delete caches folder of the android studio
Solutions for android studio 3.6 or below android studio 3.6
C:\Users\{user}\.AndroidStudio{version}\system\caches
And above android studio 3.6 or android studio arctic fox
C:\Users\{user}\AppData\Local\Google\AndroidStudio{version}\cache

Close android studio then delete the cache found in
C:\Users\**user**\.AndroidStudio3.6\system\caches
Important not to modify a file before having deleted the android studio cache
If you modify a file you risk not being able to recover your old code

Rename your project folder and delete .gradle and .idea file inside project folder

I am also facing the same issue so i am copy the files from Project location which is corrupted. In my case, there is list of files corrupted due to module added in Login Activity
build.gradle (Project)
build.gradle (App-level)
AndroidManifest.xml
activity_login.xml
ActivityLogin
Steps to solve the problem
I have deleting .iml and .idea file then restart the Android Studio.
Paste the content from Project Location which is corrupted
Commenting the code in which module classes available
Run the application
If you are using git then rollback the changes in corrupted files as copy-paste process as done in Step-2
Above one process is working for me.

It's only a project cache problem (if you see all files in Notepad, it will look fine. No file is corrupt.).
I have 100% working solution.
Close Android Studio
Copy project folder
Rename new project folder
Re-start Android Studio
File->New-> Import from new folder
Delete old folder.

Related

React-native error: Manifest merger failed

Running my app got this error:
Manifest merger failed : Attribute application#appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86
is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-117 to override.
I've tried to add to gradle.properties
android.useAndroidX=true
android.enableJetifier=true
and also (to AndroidManifest)
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
and also (to build.gradle)
implementation "androidx.appcompat:appcompat:1.0.0"
replacing the previous
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
but not working for me.
-- Android Manifest.xml --
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
-- build.gradle --
dependencies {
implementation project(':react-native-exit-app')
implementation project(':react-native-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompatv7:
${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.firebase:firebase-core:17.0.0"
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.firebase:firebase-database:18.0.0'
}
It means that one of your libraries is using AndroidX. So, you have to convert your app to AndroidX.
android.useAndroidX=true android.enableJetifier=true Put these lines in your gradle.properties.
npm install --save-dev jetifier
npx jetify
npx react-native run-android (your app should correctly compile and work)
Call npx jetify run in the postinstall target of your package.json (Any time your dependencies update you have to jetify again)

Manifest Merge issues with Lottie

I was getting started with Lottie when I came across this error. I added the dependency to my build.gradle
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.jsoup:jsoup:1.11.2'
implementation 'com.airbnb.android:lottie:2.8.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha06'
implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha06'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
Since I added implementation 'com.airbnb.android:lottie:2.8.0' build succeeds but I cant run my application as there is an error in the Manifest Merging.
Merging Errors: Error: Attribute application#appComponentFactory value=(androidx.core.app.CoreComponentFactory) from AndroidManifest.xml:22:18-86 is also present at AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:14:5-35:19 to override. app main manifest (this file), line 21
Here is my Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
xmlns:tools="http://schemas.android.com/tools"
package="com.rishav.sanfoundryfer">
<dist:module dist:instant="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:logo="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".QuestionActivity"
android:label="MCQs"/>
<activity android:name=".TopicActivity"
android:label="Select Topic"/>
<activity android:name=".SubjectActivity"
android:label="Select Subject"/>
<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>
The fact that the error has androidx.core.app.CoreComponentFactory points to the fact that the new "Jetpack" support library packages are being used. Seeing that your manifest uses the "older" packages points to the fact that it probably is used by lottie.
You can make sure that this is the reason by inspecting the library.
To resolve the issue you can use an older lottie library, start using the jetpack support library packages or resolve the merge manually. You can take a look at the merged manifest if you navigate to the AndroidManifest.xml and switch to the Merged Manifest tab at the bottom of the window.
Suggestion:
add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:14:5-35:19 to override.app main manifest (this file), line 21

Unresolved package "generated" in AndroidManifest.xml

In my Android Studio androidManifest.xml file, I found an unresolved package generated. How can I fix it?
The issued code is : android:name=".provider.generated.SquawkProvider
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.aaa">
<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>
<provider
android:name=".provider.generated.SquawkProvider"
<!-- shows unresolved package "generated" -->
android:authorities="com.example.android.aaa.provider.provider"
android:exported="false" >
</provider>
<activity
android:name=".following.FollowingPreferenceActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<service
android:name=".fcm.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
This issue stems from annotation processing now being included in Gradle from version 2.2. You can fix project and get it running with the following changes.
Project level "build.gradle" remove this line:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2'
App level "build.gradle" remove this line:
apply plugin: 'android-apt'
and change this line replacing apt with annotationProcessor:
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
In build.gradle(Module:app)
remove this two line
1) Top on the file
apply plugin: 'android-apt'
2) in dependencies
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
add this
annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.6.3'
If the above responses don't work for you, make sure you are using the latest version of Android Studio and gradle plugin (4.4 as of this post) and have changed all the 'compile' lines with 'implementation'.
After that try Build -> Clean Project then Build -> Rebuild Project. (All of this after following #drspaceboo's answer of deleting classpath and plugin lines, then changing apt to annotationProcessor.)
Try this:-
Go to File -> Invalidate Caches / Restart and then Invalidate and Restart.

Amazon Device Messaging Stub! Android Studio

I'm trying to integrate Amazon Device Messaging with Android Studio. First I followed (integrating-your-app-with-adm). When I call
ADM adm = new ADM(getActivity());
if (adm.isSupported()) {
// ...
}
There's this output on logcat:
E/AndroidRuntime(24472): java.lang.RuntimeException: Stub!
E/AndroidRuntime(24472): at com.amazon.device.messaging.ADM.(Unknown Source)
So I followed Amazons (Integrating Amazon Libraries with Android Studio ) with the same result.
Then I tried this and this without success.
My AndroidManifest.xml looks like this:
...
<uses-permission android:name="de.mypackage.permission.RECEIVE_ADM_MESSAGE" />
<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<permission android:name=".permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
...
<application
android:name=".MyPackageApplication"
android:allowBackup="true"
android:allowClearUserData="true"
android:hardwareAccelerated="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
...
<service android:name=".service.ADMNotificationService" android:exported="false" />
<amazon:enable-feature android:name="com.amazon.device.messaging" android:required="true" />
<receiver android:name=".service.ADMNotificationService$MessageAlertReceiver"
android:permission="com.amazon.device.messaging.permission.SEND">
<intent-filter>
<action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
<action android:name="com.amazon.device.messaging.intent.RECEIVE" />
<category android:name="de.mypackage"/>
</intent-filter>
</receiver>
...
</application>
The local build.gradle looks like this:
...
dependencies {
...
provided files('libs/amazon-device-messaging-1.0.1.jar')
...
}
May you have an idea?
You probably have something along this lines in your dependencies section:
compile fileTree(include: ['*.jar'], dir: 'libs')
This means you're compiling all jars in libs folder into your app. So probably the answer that says switch compile to provided works, but in addition to provided you do compile for all jars in libs folder anyway.
You would need to remove the fileTree line, and include any jars you have there (excluding amazon-device-messaging-1.0.1.jar) manually.
The solution to fix the crash is to edit the build.gradle (Module:app) file.
Remove the line: compile fileTree(include: ['.jar'], dir: 'libs')*
Go to the libs folder and find out all the jar files you require
Include them one by one for compilation. For example, compile files('libs/ePOS2.jar')
Add ADM jar file provided files('libs/amazon-device-messaging-1.0.1.jar')
Build the project

AdMob error: Didn't find class "com.google.ads.AdView"

So I'm on Android Studio v 0.3.6 and I'm having problems with Google Play Services. I was already using the Admob jar in my project but I had to update it so I tried to add them via the instructions. My project compiles fine however when I try to run an activity I get the following error:
Didn't find class "com.google.ads.AdView" on path: /data/app/com.mre. example-1. apk
See the full error output here Relevant portion of my build.gradle:
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.google.android.gms:play-services:4.0.30'
//compile project(':libraries:google-play-services_lib')
//compile files('libs/google-play-services.jar')
...
}
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
}
Here's my manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"ex">
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data
android:name="com.google.android.gms.appstate.APP_ID"
android:value="#string/app_id" />
...
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
Here's the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
...
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="50dp"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_unit_id"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
android:gravity="center" />
...
</RelativeLayout>
Over the past two days I have tried every variation of adding the GPS library to my project, to just the jar to both to none. At first I deleted the jar from my /libs and added the required lines to my build.gradle but that didn't work either. I thank you in advance for any help you can provide.
The package changed to com.google.android.gms.ads.AdRequest and com.google.android.gms.ads.AdView
Change your import and your layouts
Follow this tutorial to migrate your apk.
In my case I forget to add google_play_services_lib to my project. I fixed that by adding this library... Hope it will help someone...
Landed in similar problem while configuring firebase. Need to add play-services as dependency in app level gradle file -
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services:9.0.0'
}
Important part here is -
compile 'com.google.android.gms:play-services:9.0.0'
Post this sync your project and all required classes should be available.

Categories

Resources