Just trying to implement SafetyNet Safe Browsing API in an Android app and also read the documentation on : https://developer.android.com/training/safetynet/safebrowsing.html but i am unable to reference SafetyNet class
E.g : They say on documentation :
To use the Safe Browsing API, you must initialize the API by calling
initSafeBrowsing() and waiting for it to complete. The following code
snippet provides an example:
Tasks.await(SafetyNet.getClient(this).initSafeBrowsing())
I have searched for this API lib to reference SafetyNet class object but i am unable to reference it.
I have tried to add in my build.gradle :
implementation 'com.google.apis:google-api-services-safebrowsing:v4-rev20190923-1.30.3'
and
apply plugin: 'com.google.gms.google-services'
But still unable to find that class.
Anyone know how to implement this lib helper?
Ok, such a amateur mistake :D .....
Instead of
implementation 'com.google.apis:google-api-services-safebrowsing:v4-rev20190923-1.30.3'
I should use
implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
But they didn't mention that on the official documentations :D, hope to be useful for anyone when being confuse sometimes
There is a problem with the dependency package of safetynet. You can refer to the example code of safetynet on GitHub:
https://github.com/googlesamples/android-play-safetynet/blob/master/client/java/SafetyNetSample/Application/build.gradle
dependencies {
compile "com.android.support:support-v4:$support_version"
compile "com.android.support:support-v13:$support_version"
compile "com.android.support:cardview-v7:$support_version"
compile "com.android.support:appcompat-v7:$support_version"
compile "com.google.android.gms:play-services-safetynet:$google_play_services_version"
}
Definition of google_play_services_version:
ext.google_play_services_version = '11.0.1'
Related
I am trying to run android material design same taken from below https://github.com/material-components/material-components-android
but getting these errors :
failed
:lib:packageDebugResources
tokens.xml
Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_sys_color_dark_surface_tint">?attr/colorPrimary</macro>'
fab_tokens.xml
Can't determine type for tag '<macro name="m3_comp_fab_primary_container_color">?attr/colorPrimaryContainer</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_comp_switch_selected_icon_color">?attr/colorOnPrimaryContainer</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_sys_motion_path">linear</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_sys_shape_corner_full_family">rounded</macro>'
tokens.xml
Can't determine type for tag '<macro name="m3_ref_typeface_brand_regular">sans-serif</macro>'
/Users/mac/AndroidStudioProjects/material-components-android/lib/java/com/google/android/material/bottomappbar/res/values/tokens.xml: Error: Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'
I got the same error when upgrade to this version
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.8.0-alpha01'
But working fine in
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
Problem is solve after using current version of android studio ( updated from 4.2 to 2021.2.1 and used recommended gradle plugin )
Got the below reply from github when i open defect for same
"The error message you attached says not recognizing resource tag, which requires AGP 7.2. You must use a version later than 1.7.0-alpha02, please make sure your app build with the minimum required plugin versions."
updating the Android Gradle plugin to 7.3.3 (gradle-7.3.3-bin.zip)
things will be ok.
Replace :
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
with:
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
in build.gradle(:app) file under dependencies { }
Try downgrading material design library in build.gradle(app).
I have changed
implementation 'com.google.android.material:material:1.7.0'
to
implementation 'com.google.android.material:material:1.6.0'
And this resolved my issue.
This issue should be relevant to people who dig deeper and do not directly work with these dependencies, as it works fine for building and running apps in Android Studio.
It seems that material 1.7.0 is using illegal tag <macro>, you can see it in multiple files when looking through their release changes, specifically the **/tokens.xmlfiles. I could not find any information about this tag in AGP documentation and the only references to it I found from this git repo was this part of the code
private fun parseMacro(
element: StartElement, eventReader: XMLEventReader, parsedResource: ParsedResource): Boolean {
...
// Macros can only be defined in the default config
val defaultConfig = ConfigDescription()
if (parsedResource.config != defaultConfig) {
logError(
blameSource(source, element.location),
"<macro> tags cannot be declared in configurations other than the default configuration")
return false
}
So I'm not really sure how did they work around it.
In the future it is possible that AGP will support this tag externally and include it in their documentation, but for now you'll have to use workarounds
I intent to use the Fuel library inside an Android project.
I added the following to my Gradle file:
//core
implementation 'com.github.kittinunf.fuel:fuel:2.1.0'
//packages
implementation 'com.github.kittinunf.fuel:fuel-android:2.1.0'
implementation 'com.github.kittinunf.fuel:fuel-json:2.1.0'
It was succesfully resolved.
I copied the quick start code to a class, and when I try to compile, I get the following:
What else is required?
Make sure you are importing:
import com.github.kittinunf.result.Result
Otherwise it tries to use Kotlin's Result class.
I'm working in a massive use app that has been working for about 4 years, in the last release was implemented some new libraries, after that implementation we have facing some issues when trying to check if Google Play Services are available, this only happens on Huawei devices with Android 8+. The logcat show us this stack trace
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 12451000 but found 4323000. You must have the following declaration within the element:
We have the correct values on manifest:
<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="XXXXXXXXXXXXXXXXXXXXXX" />
If we follow the value of google_play_services_version, we can found the expected value from play-services-basement-16.1.0.aar
<integer name="google_play_services_version">12451000</integer>
This are the libs implemented on gradle
implementation "com.android.support.constraint:constraint-layout:$constraint"
implementation "com.android.support:appcompat-v7:$support"
implementation "com.android.support:design:$support"
implementation "com.android.support:cardview-v7:$support"
implementation "com.android.support:recyclerview-v7:$support"
implementation "com.android.support:design:$support"
implementation "com.android.support:support-v4:$support"
implementation "com.android.support:mediarouter-v7:$support" //New Lib
implementation "com.android.support:animated-vector-drawable:$support" //New Lib
implementation "com.android.support:design:$support"
implementation "com.android.support:support-vector-drawable:$support"
//Play services
implementation "com.google.android.gms:play-services-maps:$playServices"
implementation "com.google.android.gms:play-services-analytics:$playServices"
implementation "com.google.android.gms:play-services-gcm:$playServices"
implementation "com.google.android.gms:play-services-safetynet:$playServices"
implementation "com.google.android.gms:play-services-wearable:$playServices"
With this versions
ext {
//build
sdkCompileVersion = 27
sdkMinVersion = 16
sdkTargetVersion = 27
sdkBuildToolsVersion = '27.0.3'
//dependencies
support = '27.1.0'
playServices = '16.0.0'
newRelic = '5.18.0'
constraint = '1.1.2'
}
Does anyone have an idea how to solve this issue?
Did you hardcode value of gms version anywhere in your application? Something like this
applicationInfo.metaData.putInt("com.google.android.gms.version", 4323000);
It is also possible that one of the new libraries that you added also declares an older/different com.google.android.gms.version.
If it is happening on Huawei only, then it’s possible that Huawei is attempting to override with some value.
To confirm whether it’s your own libraries or Huawei, you will have to hardcode it into the manifest, then analyze your built apk and inspect the final value that’s merged in there. If that value is as expected, then it’s probably Huawei’s doing.
You can also try this link:
https://stackoverflow.com/a/52249677/6668797
If a library is using an old/different version, then this will override it with yours.
If it is still not resolve the issue, can you please provide the following details:
Please share the complete stack trace.
Is it happening on any Nexus/Pixel devices?
Which of those libraries are newly added?
I am trying to reference the Fitness.SENSOR_API as documented (https://developers.google.com/android/reference/com/google/android/gms/fitness/Fitness.html#SENSORS_API).
In java I import
import com.google.android.gms.fitness.Fitness;
and reference it like
Fitness.SENSORS_API
but this doesn't seem to work in nativescript (referencing it as com.google.android.gms.fitness.Fitness.SENSORS_API).
I've logged the value :
console.log('fitness native module:',
com.google.android.gms.fitness.Fitness); //Fitness is undefined
The same is true for other classes in the com.google.android.gms.fitness package for example com.google.android.gms.fitness.FitnessOptions as referenced here: https://developers.google.com/android/reference/com/google/android/gms/fitness/FitnessOptions.Builder
Overall, Here is what I'm trying to do:
googleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(activity)
.addApi(com.google.android.gms.fitness.Fitness.SENSORS_API)
.addApi(com.google.android.gms.fitness.Fitness.HISTORY_API)
.addApi(com.google.android.gms.fitness.Fitness.RECORDING_API)
.addScope('https://www.googleapis.com/auth/fitness.activity.read')
.addScope('https://www.googleapis.com/auth/fitness.activity.write')
.addScope('https://www.googleapis.com/auth/fitness.location.read')
.build();
I do have
dependencies {
implementation 'com.google.android.gms:play-services-fitness:16.0.1'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
}
in my App_Resources/Android/app.gradle file.
Am I missing something? Do I need to extend or implement some class? Why is Fitness undefined?
My overall goal is to follow these docs (https://developers.google.com/fit/android/get-started) and connect to google fitness API
Try a clean build to make sure the dependencies are installed properly, accessing the package might return undefined only in such cases.
tns platform clean android
On 7th May, 2019 androidx.lifecycle:*:2.2.0-alpha01 was released announcing:
This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here.
On documentation it's mentioned that I can get the LifecycleScope:
either via lifecycle.coroutineScope or lifecycleOwner.lifecycleScope properties
But it seems that I'm not able to find none of them. My current dependencises are:
def lifecycle_ver = "2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_ver"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_ver"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_ver"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1'
What may be the cause and how do get these apis?
I actually spent a couple hours trying to figure this out myself and it turns out it is in a new package that only exists as of the alpha. Add this and you should be good to go.
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_ver"
The accepted answers is working, but I'm misused for the first time, so I'm trying to make it clear, the current version of lifecycle is "2.1.0" and lifecycleScope, and ViewModelScope is not available in this version, to get them use
For ViewModelScope,
use androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-beta01 or higher.
For LifecycleScope,
use androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha01 or higher.
at this time 2.4.1 is available.
I've just added this two lines of code to my build.gradle (App) and that worked like a charm. I can import lifecycleScope without any problems.
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'