Android Studio showing Errors(Missing Translation) after Updating - android

Recently I have Updated my Android Studio from 2.2.3 to 2.3.0 project was running fine in 2.2.3 but after updating project dependency classpath from 2.2.3 to 2.3.0 getting lots of Missing Translations error from string.xml.
Can anyone tell me why it is happening and How to Resolve these Errors ?

Have many methods to fix this:
First method:
Add to build.gradle:
android {
lintOptions {
disable 'MissingTranslation'
}
}
Second method:
It's the ignore attribute of the tools namespace in your strings file, as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation" >
<!-- your strings here; no need now for the translatable attribute -->
</resources>
Third method:
In your ADT go to window->Preferences->Android->Lint Error Checking
Find there Missing Translation and change its Severity to Warning.
Reference link:
http://www.fasteque.com/missingtranslation-issue-for-release-builds/
Hope it helpful for you.

I was facing the exact same issue. Based on my observation, this problem was introduced with Gradle plugin version 2.3.0. It occurs when there is a module in your project that supports more languages than your app or other modules. You could start editing the translations of such modules but that makes them less maintainable.
If you disable the Lint checks using any of the suggestions here or for similar questions you also ignore actual translation errors in your app where a translation is missing for a language you are supporting. You need to be very careful maintaining your strings after that.
There is one more, also suboptimal, option: change the plugin version back to the last one not showing these symptoms in your build.gradle.
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
There is however a way to make this work without losing vital warnings/errors and without reverting to old tool versions. You can find it in Google's documentation and also in this answer.
android {
defaultConfig {
...
resConfigs "en", "fr"
}
}
This removes not needed resources and the warnings and errors along with them. I have updated my code and it builds fine now.
There is another issue that was introduced with the new Gradle plugin version: If you get false positives, i.e. errors complaining about missing translations for a string you have marked non-translatable, check if the string name exists in another module. In that case rename or provide the translations and the error disappears.

Related

Gradle Kotlin DSL: Inspection "Newer Library Versions Available" not working

I have converted my Gradle build scripts to the Kotlin DSL. Since I was starting with a small new project, everything went according to plan. When referencing more and more dependencies I wanted to put their version numbers in the script as constants, especially for those versions which are used in several places.
In my app/build.gradle.kts I have basically the following:
dependencies {
implementation("androidx.appcompat:appcompat:1.0.0")
...
}
Android Studio inspections tell me, that I should upgrade to 1.1.0. I changed it to
val appCompat = "1.0.0"
dependencies {
implementation("androidx.appcompat:appcompat:$appCompat")
...
}
but now I do not get that inspection hint anymore.
I compared my Kotlin script to what I find in the Sunflower reference project and found it to be working there. So, I experimented with defining extra-values with
extra.apply {
set("appCompat", "1.0.0")
}
implementation("androidx.appcompat:appcompat:${extra["appCompat"]}")
but got no inspection hint either.
To me, it seems that the inspection is broken using the Kotlin DSL. Do you agree or do you have a working setup for this?
In my environment inspection is broken also. So I used from third-party plugin and run it task in some interval for checking available update and manage it.
More details: https://github.com/jmfayard/gradle-dependencies-plugins

Android Studio and Kotlin code inspection is unusable when there are multiple errors in file

In Kotlin files when I have multiple errors, Android Studio becomes unusable.
When I make any change everything freezes for a few seconds, when I disable code inspection then it works normally.
This does not happen with java
Is this an issue with my pc or Kotlin or android studio, and is there any kind of a solution
Did you update your kotlin version?
I passed over a similar problem because of updating some implements or kotlin,google-services version etc. in the middle of a project!
After i returned the previous version; it is fixed...
So try using previous version for example kotlin_version = '1.3.40' in the project's build.gradle.
buildscript {
ext.kotlin_version = '1.3.40'
...
...
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
...
It might not be an issue with Kotlin.
Ensure that both the Kotlin plugin and Android Studio plugins are up to date.
The IDE can hang if it does not have enough memory allocated.
To change the memory allocation, go to Edit -> Edit Custom VM option and update the memory allocation as shown in the image below. This might help.
If you need additional assistance finding this setting, please refer to the official Android Studio Configuration guide.

Android Studio Setup Issues

I am trying to get started with Android Studio
I have installed it on several PCs and have used fresh downloads and I keep getting the same issues:
- Cannot resolve symbol 'fun' or Cannot resolve symbol 'view'. I guess this may be all symbols but these at the only ones I am trying to use now
- Objects do not show up on screen when I am trying to design apps
As I said, I have done this on several PCs now and have tried many steps suggested on SO and other forums (such as Cleanup, Invalidate Cache, adding SDKs, etc) and still get the same results.
Each time these have been clean installs with default settings so I think I must be missing a step or something.
Any advice?
Ta
Make sure your project level build.gradle contain the gradle version same as android studio version
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3' //3.1.3 is the android studio version
}
}
If you are getting "Cannot resolve symbol 'fun'", you might be trying to use Kotlin code in an Android Studio setup expecting Java. You could either change your setup to accept Kotlin or switch to using Java in your project.
The other unresolved symbol "view" probably just needs to be added as an import, you can do this by hovering over it and pressing Alt+Enter to automatically add the class to your imports.

Build error with Android Studio 3.0 Canary 4

I am currently in the process of developing an Instant app, for which I have restructured my monolithic app into feature modules.
Everything was up and running till Android Studio canary 3, but after an update to Android Studio Canary 4 my project fails to build with the following error:
A problem was found with the configuration of task ':minimoBase:dataBindingExportBuildInfoDebugAndroidTest'.
> Directory '/Users/nayak.vishal/projectData/minimo_instant_app_project/putica-client-android-
native/minimoBase/build/intermediates/data-binding-info/androidTest/debug'
specified for property 'xmlOutFolder' does not exist.
The following procedure worked as a workaround for this issue:
Execute the following build commands on the gradle command line
1) gradlew clean
2) gradlew :appModule:assembleDebug
here appModule is the name of the app module for building the installable apk
the build is successful and the debug apk generated in the output folder can be installed successfully
3) gradlew :instantAppModule:assembleDebug
here instantAppModule is the name of the instant app module
the build is successful and the instant app apks can be installed and launched via deep link
Once the above command line builds are successful, building via Android Studio Canary 4 also stops throwing the build error.
I got similar error when I turn on data-binding for library module. When I turn it off and move all classes that require data-binding to app module, it works. So I guess there is a problem that DataBinding doesn't work on Library module any more ( Gradle 2.x fine with this).
dataBinding {
enabled = false
}
I am using com.android.tools.build:gradle:3.0.0-alpha5 and Android Studio 3.0 Preview Canary5
UPDATE
Although the original answer worked, I really want to turn on data-binding on my library module, where I implement some base classes using binding technique. I move them back to library module and upgrade kotlin version to the latest one 1.1.3-2. Suddenly it works also. I am not sure which one is the better but both ways work for me.
UPDATE 2
I am using com.android.tools.build:gradle:3.0.0-alpha9 and kotlin 1.1.3-2 at this time and suddenly the problem re-appear.
Now I think the problem doesn't come from Kotlin. My library module turned dataBiding { enabled=true}, but it doesn't have any layout file. I tried to create a fake layout file wrapped by <layout> tag and it works
<?xml version="1.0" encoding="utf-8"?>
<layout>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</layout>
In your gradle.properties file , add the following line
android.enableAapt2=false
Recent versions of AS3.0 switched to using AAPT2 by default.
You can disable AAPT2 in your gradle.propertіes fіle with above mentioned line of code, and continue developing on AS3 canary 4.
This was an issue for me when I had a "base" feature module without any layouts (all my actual layouts are in separate features)
Adding a dummy layout XML file in the base feature (e.g. as base/src/res/layout/dummy.xml) meant the missing directory was created and the app compiled.
(this is using com.android.tools.build:gradle:3.0.0-alpha6)
I've had the same problem, seems like a bug in Canary 4.
For now, as a workaround, I downgraded to Android Studio 3.0.0 Canary 3 (This is an archive of all Android Studio releases) and also downgraded the Android Gradle plugin to 3.0.0-alpha3:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
...
}
Updated:
Just check the Canary version after update. For that see Android Studio version just above the toolbar (File..Edit..View..line) where name at end like "Canary X".-> X is number like 3,4,5,etc.
For example suppose updated version(X) is 5.
Try to change that classpath in build.gradle(applicationName) to 3.0.0-alpha5 and sync(/Try) again:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha5'
}
Means that updated version(X):-
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alphaX'
}

Can't generate APK Release because of GCM SenderId Android

I have implemented GCM (Google Cloud Messaging) in my app. Google Play Services library has auto-generated values.xml in which my senderId is :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="gcm_defaultSenderId">123</string>
</resources>
The problem is that I have other locale, and Lint during App Release is giving me an error :
Error:(3) Error: "gcm_defaultSenderId" is not translated in "fr" (French) [MissingTranslation]
Because it is automaticaly generated I can't set translable = false. How I should fix this?
Add a lint.xml file in your project application root (under app/) and add the missing translations to be ignored there:
<lint>
<issue id="MissingTranslation">
<ignore regexp="ga_trackingId"/>
<ignore regexp="gcm_defaultSenderId"/>
<ignore regexp="google_app_id"/>
</issue>
</lint>
These will now be ignored by lint - you can configure which properties to ignore, and you won't have to wait for updates from the google-services team for properties that they haven't thought of.
Lint-ing will still catch all other errors, so you can still enjoy the other features.
I assume that you are using Android Studio.
Had the exact same problem with Android Studio 1.4.
First thing I tried was to edit the "File - Settings - Editor - Inspections - Android Lint - Incomplete Translation" Severity Setting to something other then 'Error'.
That did not help! I still was not able to build a release APK.
I ended up 'translating' the XML as follows:
in the folder .../android/res create a new language folder values-de (replace de with your language code).
create a file named google-services.xml in the language folder.
Insert into the xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="gcm_defaultSenderId"><YOUR_SENDERID></string>
</resources>
After that I was able to build the release.
Since the last update of Android Studio (1.5) I had this issue too. I solved it by updating the Google Services dependencies to the latest version.
According to this link, indeed,
This issue should be fixed with 8.3.0 Google Play Services and 1.5.0-beta2 dependency.
Hope this helps! :)
EDIT Integration: actually, while the gcm_defaultSenderId string is now generated correctly (with translatable="false" attribute), google_app_id and ga_trackingID strings, for instance, are not.
For those still having issues, I came to the conclusion that we have to wait for Google guys to fix this issue and ignore the error in the meantime by adding to the app level build.gradle file
...
android {
lintOptions {
abortOnError false
}
}
...
you will probably have another bit of autogenerated code like this:
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Get a valid sender id from the google cloud console then you can remove the R.string.gcm_defaultSenderId from the above code and also the gcm_defaultSenderId from the resource file.
If you want/need upgrade to newer version of:
lint (androidstudio with build-in lint)
build tools
compileSdkVersion
gradle plugin
gradle
google-services (plugin)
google-services dedendencies (e.g. play-services-gcm)
(unfortunatelly) other dependencies if are transitivelly dependent to google-services
you need to choose wiselly versions of all these parts together. Since these all needs to be compatible together. Unfortunatelly, there is no compatibility table (the only I found is more a year old, so I do not link it here. If anybody know any please share a link).
So, solution is investigate which verstion of which part blocks anything else. Which could be nightmare, so a lot of advice is to revert to last known funcional configuration. But sooner or later we will be force to upgrade.
I checked home pages of each part to find any version info, but at last I still solve it by test-and-try method.
Here is what is functional for me:
androidstudio 1.5
build tools 23.0.2
compileSdkVersion 23
gradle plugin 1.5.0
gradle 2.8
google services plugin 1.5.0
google services dependencies 8.3.0
lucky, no other external GS dependencies (obviously all internal modules needs to use same version)

Categories

Resources