问:
How to Locate Timestamps of a Subset of a Video
I have never done any video-based programming before, and although this SuperUser post provides a way to do it on the command line, I prefer a programmatic approach, preferably with Python.

I have a bunch of sub-videos. Suppose one of them is called 1234_trimmed.mp4 which is a short segment cut from the original, much-longer video 1234.mp4. How can I figure out the start and end timestamps of 1234_trimmed.mp4 inside 1234.mp4?

FYI, the videos are all originally on YouTube anyway ("1234" corresponds to the YouTube video ID) if there's any shortcut that way.

答:
I figured it out myself with cv2. My strategy was to get the first and last frames of the subvideo and iterate over each frame of the original video, where I compare the current frame's dhash (minimum hamming distance instead of checking for equality in case of resizing and other transformations) against the first and last frames. I'm sure there may be some optimization opportunities but I need this yesterday.

import cv2

original_video_fpath = '5 POPULAR iNSTAGRAM BEAUTY TRENDS (DiY Feather Eyebrows, Colored Mascara, Drippy Lips, Etc)-vsNVU7y6dUE.mp4'
subvideo_fpath = 'vsNVU7y6dUE_trimmed-out.mp4'

def dhash(image, hashSize=8):
    # resize the input image, adding a single column (width) so we
    # can compute the horizontal gradient
    resized = cv2.resize(image, (hashSize + 1, hashSize))
    # compute the (relative) horizontal gradient between adjacent
    # column pixels
    diff = resized[:, 1:] > resized[:, :-1]
    # convert the difference image to a hash
    return sum([2 ** i for (i, v) in enumerate(diff.flatten()) if v])

def hamming(a, b):
    return bin(a^b).count('1')

def get_video_frame_by_index(video_cap, frame_index):
    # get total number of frames
    totalFrames = video_cap.get(cv2.CAP_PROP_FRAME_COUNT)

    if frame_index < 0:
        frame_index = int(totalFrames) + frame_index

    # check for valid frame number
    if frame_index >= 0 & frame_index <= totalFrames:
        # set frame position
        video_cap.set(cv2.CAP_PROP_POS_FRAMES, frame_index)

    _, frame = video_cap.read()
    return frame

def main():
    cap_original_video = cv2.VideoCapture(original_video_fpath)

    cap_subvideo = cv2.VideoCapture(subvideo_fpath)

    first_frame_subvideo = get_video_frame_by_index(cap_subvideo, 0)
    last_frame_subvideo = get_video_frame_by_index(cap_subvideo, -1)

    first_frame_subvideo_gray = cv2.cvtColor(first_frame_subvideo, cv2.COLOR_BGR2GRAY)
    last_frame_subvideo_gray = cv2.cvtColor(last_frame_subvideo, cv2.COLOR_BGR2GRAY)

    hash_first_frame_subvideo = dhash(first_frame_subvideo)
    hash_last_frame_subvideo = dhash(last_frame_subvideo)

    min_hamming_dist_with_first_frame = float('inf')
    closest_frame_index_first = None
    closest_frame_timestamp_first = None

    min_hamming_dist_with_last_frame = float('inf')
    closest_frame_index_last = None
    closest_frame_timestamp_last = None

    frame_index = 0
    while(cap_original_video.isOpened()):
        frame_exists, curr_frame = cap_original_video.read()

        if frame_exists:
            timestamp = cap_original_video.get(cv2.CAP_PROP_POS_MSEC) // 1000

            hash_curr_frame = dhash(curr_frame)

            hamming_dist_with_first_frame = hamming(hash_curr_frame, hash_first_frame_subvideo)
            hamming_dist_with_last_frame = hamming(hash_curr_frame, hash_last_frame_subvideo)

            if hamming_dist_with_first_frame < min_hamming_dist_with_first_frame:
                min_hamming_dist_with_first_frame = hamming_dist_with_first_frame
                closest_frame_index_first = frame_index
                closest_frame_timestamp_first = timestamp

            if hamming_dist_with_last_frame < min_hamming_dist_with_last_frame:
                min_hamming_dist_with_last_frame = hamming_dist_with_last_frame
                closest_frame_index_last = frame_index
                closest_frame_timestamp_last = timestamp

            frame_index += 1
        else:
            print('processed {} frames'.format(frame_index+1))
            break

    cap_original_video.release()
    print('timestamp_start={}, timestamp_end={}'.format(closest_frame_timestamp_first, closest_frame_timestamp_last))

if __name__ == '__main__':
    main()
```


来源: stackexchange

问:
Duplicate class build error when adding firebase with play-services-ads
I have tried to connect firebase to my existing android project with Admob integration and I got the following error stack when build the project. </p>

```<code>Duplicate class com.google.android.gms.internal.measurement.zzdi found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdj found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdk found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdl found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdm found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdn found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdo found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdp found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdq found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdr found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzds found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdt found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdu found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdv found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdw found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzfq found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfr found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfs found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzft found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfu found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfv found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfw found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfx found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfy found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfz found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzga found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgd found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzge found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgg found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgh found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgi found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgj found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgk found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgl found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzu found in modules classes.jar (com.google.android.gms:play-services-measurement-sdk-api:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.internal.measurement.zzv found in modules classes.jar (com.google.android.gms:play-services-measurement-sdk-api:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.internal.measurement.zzw found in modules classes.jar (com.google.android.gms:play-services-measurement-base:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$ConditionalUserProperty found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$Event found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$EventInterceptor found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$OnEventListener found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$Param found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$UserProperty found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurementContentProvider found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurementJobService found in modules classes.jar (com.google.android.gms:play-services-measurement:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.AppMeasurementReceiver found in modules classes.jar (com.google.android.gms:play-services-measurement:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.AppMeasurementService found in modules classes.jar (com.google.android.gms:play-services-measurement:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zza found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaa found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzab found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzac found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzad found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzae found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzag found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzah found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzai found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaj found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzak found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzal found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzam found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzan found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzao found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzap found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaq found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzar found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzas found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzat found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzau found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzav found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzaw found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzax found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzay found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzaz found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzba found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbd found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbe found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbg found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbh found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbi found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbj found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbk found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbl found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbm found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbn found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbo found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbp found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbq found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbr found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbs found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbt found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbu found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbv found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbw found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbx found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzby found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbz found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzca found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcd found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzce found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcg found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzch found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)

</code>```

<p>Basically I want to add Admob rewards adz in my app so I had to use
<code>implementation 'com.google.android.gms:play-services-ads:18.2.0'</code></p>

<p>It seems to be there is a complict with <code>implementation 'com.google.android.gms:play-services-ads:18.2.0'</code> and <code>implementation 'com.google.firebase:firebase-invites:16.0.4'</code></p>

<p><strong>Gradle file</strong></p>

```<code>apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.vivo.proj.firebase_example"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.firebase:firebase-invites:16.0.4'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
</code>```

<p>Could please help me to solve this issue.</p>

答: Go to Build.gradle and update Firebase implementation to new version. That works for me.

ContentLicense: CC BY-SA 4.0

Body:
I have tried to connect firebase to my existing android project with Admob integration and I got the following error stack when build the project.

Duplicate class com.google.android.gms.internal.measurement.zzdi found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdj found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdk found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdl found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdm found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdn found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdo found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdp found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdq found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdr found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzds found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdt found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdu found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdv found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzdw found in modules classes.jar (com.google.android.gms:play-services-appinvite:16.0.4) and classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzfq found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfr found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfs found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzft found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfu found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfv found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfw found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfx found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfy found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzfz found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzga found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgd found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzge found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgg found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgh found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgi found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgj found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgk found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzgl found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.internal.measurement.zzu found in modules classes.jar (com.google.android.gms:play-services-measurement-sdk-api:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.internal.measurement.zzv found in modules classes.jar (com.google.android.gms:play-services-measurement-sdk-api:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.internal.measurement.zzw found in modules classes.jar (com.google.android.gms:play-services-measurement-base:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$ConditionalUserProperty found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$Event found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$EventInterceptor found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$OnEventListener found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$Param found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurement$UserProperty found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurementContentProvider found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.AppMeasurementJobService found in modules classes.jar (com.google.android.gms:play-services-measurement:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.AppMeasurementReceiver found in modules classes.jar (com.google.android.gms:play-services-measurement:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.AppMeasurementService found in modules classes.jar (com.google.android.gms:play-services-measurement:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zza found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaa found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzab found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzac found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzad found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzae found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzag found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzah found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzai found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaj found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzak found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzal found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzam found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzan found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzao found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzap found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzaq found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzar found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzas found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzat found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzau found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzav found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzaw found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzax found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzay found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzaz found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzba found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbd found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbe found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbg found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbh found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbi found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbj found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbk found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbl found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbm found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbn found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbo found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbp found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbq found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbr found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbs found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbt found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbu found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzbv found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbw found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbx found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzby found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzbz found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics-impl:16.2.2)
Duplicate class com.google.android.gms.measurement.internal.zzca found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcb found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcc found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcd found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzce found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcf found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzcg found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)
Duplicate class com.google.android.gms.measurement.internal.zzch found in modules classes.jar (com.google.android.gms:play-services-measurement-impl:17.0.0) and classes.jar (com.google.firebase:firebase-analytics:16.0.4)

Basically I want to add Admob rewards adz in my app so I had to use
implementation 'com.google.android.gms:play-services-ads:18.2.0'

It seems to be there is a complict with implementation 'com.google.android.gms:play-services-ads:18.2.0' and implementation 'com.google.firebase:firebase-invites:16.0.4'

Gradle file

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.vivo.proj.firebase_example"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.firebase:firebase-invites:16.0.4'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Could please help me to solve this issue.


问:
Plotting a scatter data with error bars in x and y direction and adding a trend line
I have  a bunch of scattered data that I would like to plot and add a best fit line (y=ax+b) and represent the equation with the associated error (maybe R), and showing 95 % confidence level curves. Moreover, each point (x,y) has a name that should appear in the legend preferably each point should have different shape. Could anyone please help me out with this? </p>

```<code>x=np.array([100,65,20,85])
xerr=np.array([5,3,2,5])
y=np.array([1,0.75,1.25,2])
yerr=np.array([0.1,0.03,0.01,0])
</code>```

答:
I'm not sure what exactly you want to do. Maybe, something like this? About the 95% confidence level curves, you can take a look here How to plot confidence interval in Python?.

```<code>import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    fig = plt.figure()
    x = np.array([100,65,20,85])
    y = np.array([1,0.75,1.25,2])
    Error_x = np.array([5,3,2,5])
    Error_y = np.array([0.1,0.03,0.01,0])

    labels = ['A', 'B', 'C', 'D']
    symbols = ['v', '^', '<', '>']

    for i in range(0, len(x)):
        plt.scatter(x[i], y[i], marker=symbols[i], s=70)
        plt.errorbar(x[i], y[i], xerr=Error_x[i], c='black')
        plt.errorbar(x[i], y[i], yerr=Error_y[i], c='black')

    z = np.polyfit(x.flatten(), y.flatten(), 1)
    p = np.poly1d(z)
    plt.plot(x,p(x),"r--")

    ci = 0.95 * np.std(y)/np.mean(y)
    ax.fill_between(sorted(x), p(x)-ci, p(x)+ci, color='b', alpha=.4)

    for l in range(0, len(labels)):
        plt.text(x[l], y[l] + 0.03, labels[l])

    plt.grid()
    plt.tight_layout()
    plt.savefig("test.png")
    plt.show()
</code>```

Body:
I have  a bunch of scattered data that I would like to plot and add a best fit line (y=ax+b) and represent the equation with the associated error (maybe R), and showing 95 % confidence level curves. Moreover, each point (x,y) has a name that should appear in the legend preferably each point should have different shape. Could anyone please help me out with this?

x=np.array([100,65,20,85])
xerr=np.array([5,3,2,5])
y=np.array([1,0.75,1.25,2])
yerr=np.array([0.1,0.03,0.01,0])

Body:
I'm not sure what exactly you want to do. Maybe, something like this? About the 95% confidence level curves, you can take a look here How to plot confidence interval in Python?.

import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    fig = plt.figure()
    x = np.array([100,65,20,85])
    y = np.array([1,0.75,1.25,2])
    Error_x = np.array([5,3,2,5])
    Error_y = np.array([0.1,0.03,0.01,0])

    labels = ['A', 'B', 'C', 'D']
    symbols = ['v', '^', '<', '>']

    for i in range(0, len(x)):
        plt.scatter(x[i], y[i], marker=symbols[i], s=70)
        plt.errorbar(x[i], y[i], xerr=Error_x[i], c='black')
        plt.errorbar(x[i], y[i], yerr=Error_y[i], c='black')

    z = np.polyfit(x.flatten(), y.flatten(), 1)
    p = np.poly1d(z)
    plt.plot(x,p(x),"r--")

    ci = 0.95 * np.std(y)/np.mean(y)
    ax.fill_between(sorted(x), p(x)-ci, p(x)+ci, color='b', alpha=.4)

    for l in range(0, len(labels)):
        plt.text(x[l], y[l] + 0.03, labels[l])

    plt.grid()
    plt.tight_layout()
    plt.savefig("test.png")
    plt.show()


问:
Investigating a bad free() pointer reference
My program is crashing badly in an unitary test, due to a free() call to a bad pointer, with this error message:

```<code>*** glibc detected *** /home/user/main.out: free(): invalid pointer: 0x006d0065 ***
</code>```

The code looks roughly like this:

```<code>// constructor is MyObj( const std::string & )
// and copies the string in its own std:string member
MyObject *obj = new MyObject("some string arg");
if(obj->isValid)
{
   log("Success\n");
}
delete obj; // if I remove this, the program doesn't crash...
</code>```

My investigations have gone through this:

I tried to trace the pointers I create and free, but it occurs in a different address space, I get (successful) deletions like this: Delete buffer @0x850ed0. So I suspect something's trying to free a static char pointer. Also, the address stays the same over several attempts, which comforts me in this predicate.

I can't use GDB because the platform I'm using seems to bail out:

Program received signal SIGABRT, Aborted.

[Switching to Thread 0x344314e8 (LWP 1443)]

0x2a3dd658 in raise () from /lib/libc.so.6

(gdb) bt

#0  0x2a3dd658 in raise () from /lib/libc.so.6

#1  0x2a3dea2c in abort () from /lib/libc.so.6

Backtrace stopped: frame did not save the PC

I tried to use hexdump to dump the address in the program on which the free() fails with this: hexdump -C ~/main.out -s 0x6d0000 -n 2000

It gives me this (fault is free(0x6d0065)):

006d0060  e8 32 06 00 2c e6 02 5f  5a 4e 4b 53 73 34 66 69  |.2..,.._ZNKSs4fi|
006d0070  6e 64 45 63 6a 00 ab 00  00 00 01 3e 58 00 00 1d  |ndEcj......>X...|

Which looks like a std::string function, which is quite strange...
I figured this might be a bad use of hexdump, since the memory gets relocated when the program is loaded into memory.

I tried readelf ~/main.out -a | grep 6d0065 to no avail as well (gives no hit)

I'm not a pro on debugging in these conditions; do you have any idea of how I could get what this address means to the program?

Edit:

The program runs on an embedded platform (SH4); which is not supported by valgrind (very sadly...).

Some more details on what this class does: it uses the CUrl library to retrieve an XML file on the internet, then proceeds to parse it with the pugixml library.

答:
Ok, finally nailed the bug down.

For those interested, it was a structure that wasn't zeroed in the constructor of the class using it.

The schema was like this:

```<code>MyObj ---> BaseClass ---> structure member not initialized
</code>```

Since this structure holds some pointers to strings, the NULL-check was failing and I'd free a bad pointer.

What's sad is that the base class usually would fill up every field of the structure, overriding the default garbage values. Only when I inherited the base class did I encounter the problem.

Looking back at this, I guess I could have found it way faster with a working GDB debugging.
I guess I'll have to look into this issue.

ContentLicense: CC BY-SA 3.0

Body:
My program is crashing badly in an unitary test, due to a free() call to a bad pointer, with this error message:

*** glibc detected *** /home/user/main.out: free(): invalid pointer: 0x006d0065 ***

The code looks roughly like this:

// constructor is MyObj( const std::string & )
// and copies the string in its own std:string member
MyObject *obj = new MyObject("some string arg");
if(obj->isValid)
{
   log("Success\n");
}
delete obj; // if I remove this, the program doesn't crash...

My investigations have gone through this:

I tried to trace the pointers I create and free, but it occurs in a different address space, I get (successful) deletions like this: Delete buffer @0x850ed0. So I suspect something's trying to free a static char pointer. Also, the address stays the same over several attempts, which comforts me in this predicate.

I can't use GDB because the platform I'm using seems to bail out:

Program received signal SIGABRT, Aborted.

[Switching to Thread 0x344314e8 (LWP 1443)]

0x2a3dd658 in raise () from /lib/libc.so.6

(gdb) bt

#0  0x2a3dd658 in raise () from /lib/libc.so.6

#1  0x2a3dea2c in abort () from /lib/libc.so.6

Backtrace stopped: frame did not save the PC

I tried to use hexdump to dump the address in the program on which the free() fails with this: hexdump -C ~/main.out -s 0x6d0000 -n 2000

It gives me this (fault is free(0x6d0065)):

006d0060  e8 32 06 00 2c e6 02 5f  5a 4e 4b 53 73 34 66 69  |.2..,.._ZNKSs4fi|
006d0070  6e 64 45 63 6a 00 ab 00  00 00 01 3e 58 00 00 1d  |ndEcj......>X...|

Which looks like a std::string function, which is quite strange...
I figured this might be a bad use of hexdump, since the memory gets relocated when the program is loaded into memory.

I tried readelf ~/main.out -a | grep 6d0065 to no avail as well (gives no hit)

I'm not a pro on debugging in these conditions; do you have any idea of how I could get what this address means to the program?

Edit:

The program runs on an embedded platform (SH4); which is not supported by valgrind (very sadly...).

Some more details on what this class does: it uses the CUrl library to retrieve an XML file on the internet, then proceeds to parse it with the pugixml library.

Body:
Ok, finally nailed the bug down.

For those interested, it was a structure that wasn't zeroed in the constructor of the class using it.

The schema was like this:

MyObj ---> BaseClass ---> structure member not initialized

Since this structure holds some pointers to strings, the NULL-check was failing and I'd free a bad pointer.

What's sad is that the base class usually would fill up every field of the structure, overriding the default garbage values. Only when I inherited the base class did I encounter the problem.

Looking back at this, I guess I could have found it way faster with a working GDB debugging.
I guess I'll have to look into this issue.


问:
Kotlin Multiplatform : Plugin [id: 'com.android.library'] was not found
I am trying to set up Android Library via Kotlin Multiplatform Library.

I am getting error:

Plugin [id: 'com.android.library'] was not found in any of the following sources:

Please help me by pointing out what is wrong and how to resolve this issue.

My plugin set up is this(with supposedly proper buildscript):

```<code>plugins {
    id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
    id("com.android.library")
    id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
    id("com.squareup.sqldelight")
}
</code>```

when I replace that with following

```<code>plugins {
    id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
    id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
}

apply plugin: 'com.android.library'
apply plugin: 'com.squareup.sqldelight'
</code>```

it's working fine.
I am not sure what causes the issue.

Following is the  complete build.gradle:

```<code>buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.squareup.sqldelight:gradle-plugin:1.3.0'
        classpath 'com.android.tools.build:gradle:3.6.3'
    }
}

plugins {
    id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
    id("com.android.library")
    id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
    id("com.squareup.sqldelight")
}

repositories {
    mavenCentral()
    jcenter()
    google()
}

group 'com.jolas.sdk.kn.newsycore'
version '0.0.1'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

def ktor_version = '1.3.2'
kotlin {
    android {
        publishLibraryVariants("release", "debug")
    }
    // This is for iPhone simulator
    // Switch here to iosArm64 (or iosArm32) to build library for iPhone device
    iosX64("ios") {
        binaries {
            framework()
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation "io.ktor:ktor-client-core:$ktor_version"
                implementation "io.ktor:ktor-client-serialization:$ktor_version"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        androidMain {
            dependencies {
                implementation kotlin('stdlib')
                implementation "io.ktor:ktor-client-okhttp:$ktor_version"
                implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
                implementation "com.squareup.sqldelight:sqlite-driver:1.3.0"
            }
        }
        iosMain {
            dependencies {
                implementation kotlin('stdlib')
                implementation "io.ktor:ktor-client-ios:$ktor_version"
                implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
                implementation "com.squareup.sqldelight:native-driver:1.3.0"
            }
        }
    }
}

sqldelight {
    NewsyDatabase {
        packageName = "com.jolas.sdk.kn.newsycore"
    }
}

configurations {
    compileClasspath
}
</code>```

答:
Nelson is correct regarding the pluginManagement block, but there is an additional requirement for a plugin to be found without additional configuration. If you require plugins { id("com.android.application") version "3.6.1" }, Gradle would search for the following Maven artifact: com.android.application:com.android.application.gradle.plugin:3.6.1. This is a convention. When developing your custom plugin, Gradle's default java-gradle-plugin will provide such an artifact out of the box. See the corresponding section of Gradle docs for more details.

To override module resolution for any plugin, you can use the resolutionStrategy block. I've got the following for Android plugins:

pluginManagement {
    repositories {
        google()
        gradlePluginPortal()
        jcenter()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == "com.android") {
                useModule("com.android.tools.build:gradle:${requested.version}")
            } else if(requested.id.namespace == "com.google.gms") {
                useModule("com.google.gms:${requested.id.name}:${requested.version}")
            }
        }
    }
}
```

<p>Having this in your <code>settings.gradle.kts</code> will allow you to use the usual <code>plugins</code> block as follows:</p>

<pre class="lang-kotlin prettyprint-override"><code>plugins {
    id("com.android.application") version "3.6.1"
    id("com.google.gms.google-services") version "4.3.3"
}
</code>```

Of course, to re-use the same version of the plugin in all submodules you can go with the usual route of apply false:

/build.gradle.kts:

plugins {
    id("com.android.application") version "3.6.1" apply false
    id("com.android.library") version "3.6.1" apply false
    // ...
}
```

<p><strong>/lib/build.gradle.kts</strong>:</p>

<pre class="lang-kotlin prettyprint-override"><code>plugins {
    id("com.android.library")
    // ...
}
</code>```

Body:
I am trying to set up Android Library via Kotlin Multiplatform Library.

I am getting error:

Plugin [id: 'com.android.library'] was not found in any of the following sources:

Please help me by pointing out what is wrong and how to resolve this issue.

My plugin set up is this(with supposedly proper buildscript):

plugins {
    id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
    id("com.android.library")
    id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
    id("com.squareup.sqldelight")
}

when I replace that with following

plugins {
    id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
    id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
}

apply plugin: 'com.android.library'
apply plugin: 'com.squareup.sqldelight'

it's working fine.
I am not sure what causes the issue.

Following is the  complete build.gradle:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.squareup.sqldelight:gradle-plugin:1.3.0'
        classpath 'com.android.tools.build:gradle:3.6.3'
    }
}

plugins {
    id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
    id("com.android.library")
    id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
    id("com.squareup.sqldelight")
}

repositories {
    mavenCentral()
    jcenter()
    google()
}

group 'com.jolas.sdk.kn.newsycore'
version '0.0.1'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

def ktor_version = '1.3.2'
kotlin {
    android {
        publishLibraryVariants("release", "debug")
    }
    // This is for iPhone simulator
    // Switch here to iosArm64 (or iosArm32) to build library for iPhone device
    iosX64("ios") {
        binaries {
            framework()
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation "io.ktor:ktor-client-core:$ktor_version"
                implementation "io.ktor:ktor-client-serialization:$ktor_version"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        androidMain {
            dependencies {
                implementation kotlin('stdlib')
                implementation "io.ktor:ktor-client-okhttp:$ktor_version"
                implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
                implementation "com.squareup.sqldelight:sqlite-driver:1.3.0"
            }
        }
        iosMain {
            dependencies {
                implementation kotlin('stdlib')
                implementation "io.ktor:ktor-client-ios:$ktor_version"
                implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
                implementation "com.squareup.sqldelight:native-driver:1.3.0"
            }
        }
    }
}

sqldelight {
    NewsyDatabase {
        packageName = "com.jolas.sdk.kn.newsycore"
    }
}

configurations {
    compileClasspath
}

Body:
Nelson is correct regarding the pluginManagement block, but there is an additional requirement for a plugin to be found without additional configuration. If you require plugins { id("com.android.application") version "3.6.1" }, Gradle would search for the following Maven artifact: com.android.application:com.android.application.gradle.plugin:3.6.1. This is a convention. When developing your custom plugin, Gradle's default java-gradle-plugin will provide such an artifact out of the box. See the corresponding section of Gradle docs for more details.

To override module resolution for any plugin, you can use the resolutionStrategy block. I've got the following for Android plugins:

pluginManagement {
    repositories {
        google()
        gradlePluginPortal()
        jcenter()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == "com.android") {
                useModule("com.android.tools.build:gradle:${requested.version}")
            } else if(requested.id.namespace == "com.google.gms") {
                useModule("com.google.gms:${requested.id.name}:${requested.version}")
            }
        }
    }
}

Having this in your settings.gradle.kts will allow you to use the usual plugins block as follows:

plugins {
    id("com.android.application") version "3.6.1"
    id("com.google.gms.google-services") version "4.3.3"
}

Of course, to re-use the same version of the plugin in all submodules you can go with the usual route of apply false:

/build.gradle.kts:

plugins {
    id("com.android.application") version "3.6.1" apply false
    id("com.android.library") version "3.6.1" apply false
    // ...
}

/lib/build.gradle.kts:

plugins {
    id("com.android.library")
    // ...
}


问:
TypeError: client.guilds is not iterable(14:29)
I was adding new features to my Discord Bot then suddenly the following problem has stopped me from completing my code ! ( What is my mistake ? Where is my mistake ? How can I solve it ? )

The Problem :
UnhandledPromiseRejectionWarning: TypeError: client.guilds is not iterable(14:29)

My Code :

```<code>    1: const { SettingProvider } = require("discord.js-commando");
    2: const File = require("./File.js");
    3:
    4: module.exports = class JSONSettingsProvider extends SettingProvider {
    5:     constructor(path) {
    6:         super();
    7:         this.file = new File(path);
    8:         if (!this.file.exists) this.file.write({}, false, true);
    9:     }
    10:
    11:     init(client) {
    12:         const data = this.file.read();
    13:         const id = bot.guild("689879529493233684");
    14:         for (const [id] of client.guilds) {
    15:             if (!data[id]) data[id] = {};
    16:             if (data[id].prefix && client.guilds.has(id))
    17:                 client.guilds.get(id).commandPrefix = data[id].prefix;
    18:         }
    19:         this.file.write(data);
    20:     }
</code>```

答: Add a if condition to wrap around line 14-19 like so if (typeof client.guilds == 'object' && typeof client.guilds[Symbol.iterator] == 'function')

Body:
I was adding new features to my Discord Bot then suddenly the following problem has stopped me from completing my code ! ( What is my mistake ? Where is my mistake ? How can I solve it ? )

The Problem :
UnhandledPromiseRejectionWarning: TypeError: client.guilds is not iterable(14:29)

My Code :

    1: const { SettingProvider } = require("discord.js-commando");
    2: const File = require("./File.js");
    3:
    4: module.exports = class JSONSettingsProvider extends SettingProvider {
    5:     constructor(path) {
    6:         super();
    7:         this.file = new File(path);
    8:         if (!this.file.exists) this.file.write({}, false, true);
    9:     }
    10:
    11:     init(client) {
    12:         const data = this.file.read();
    13:         const id = bot.guild("689879529493233684");
    14:         for (const [id] of client.guilds) {
    15:             if (!data[id]) data[id] = {};
    16:             if (data[id].prefix && client.guilds.has(id))
    17:                 client.guilds.get(id).commandPrefix = data[id].prefix;
    18:         }
    19:         this.file.write(data);
    20:     }


问:
Empty PropertyConfigurator implementation in log4j-1.2-api
I'm upgrading Log4j-1.2.17 to Log4j2-2.12.2 in my project.
To do that I'm using the log4j-1.2 bridge.
In old version I use property file to configure log4j.

After upgrade everything looks ok, no errors, no warnings. But logs don't appear in file pointed in properties file.
I realized that PropertyConfigurator.class exists in log4j-1.2-api.jar, but methods don't have implementation.
empty PropertyConfigurator.configure(Properties properties)
Can you explain me that?

Which configuration syntax is correct when I use log4j-1.2-api.jar? log4j or log4j2?

答:
Prior to Log4j 2.13.0 log4j-1.2-api only provides compatibility for applications that used the log4j 1.x API for logging. The Log4j 2 configuration is still used as all logging calls are redirected to Log4j 2. So only the Log4j 2 configuration syntax would be valid.

Many of the old log4j 1.x internal classes are also present because many applications were using them in an attempt manually manipulate logging, much of which probably isn't necessary with Log4j 2.

In Log4j 2.13.0 the log4j-1.2-api was extended to provide experimental support for Log4j 1.x configuration files. You would have to compare your log4j 1 configurations with the documentation to determine if that support will work for you. However, the Log4j 1.x PropertyConfigurator still will be a no-op even with the compatibility support.


问:
react - prevent video from going fullscreen on iOS
I am making a web app with video playback and custom controls: a Next Video button and a Previous Video Button. My component looks like this:

```<code>
const videos = [
    'https://d3t1nqlebka5eu.cloudfront.net/videos3/82818a63-1972-4e39-b296-9cd3b85b0b39.mp4',
    'https://d3t1nqlebka5eu.cloudfront.net/videos3/dd4dd6c5-95b7-41c2-b131-7b62392ad1b5.mp4',
    'https://d3t1nqlebka5eu.cloudfront.net/videos3/29812506-e67d-4cab-b2b3-82461a4eadf1.mp4',
]

function App() {

    const [videoIndex, setVideoIndex] = useState(0);
    const h1Ref = useRef<HTMLVideoElement>(null);

    return (
        <div>
            <DivButton onClick={() => {
                setVideoIndex(getPrevIndex(videoIndex));
                h1Ref.current!.load();
            }}>
                Prev
            </DivButton>
            {' '}
            <DivButton onClick={() => {
                setVideoIndex(getNextIndex(videoIndex));
                h1Ref.current!.load();
            }}>
                Next
            </DivButton>
            <div>
                <video id="video_player" autoPlay muted loop playsinline preload="" ref={h1Ref}>
                    <source id="video_player_source" src={videos[videoIndex]} type="video/mp4"/>
                </video>

            </div>

        </div>
    );
}
</code>```

The problem is this: when I click Next or Prev buttons, the videos do switch between one another, but after every switch they are entering fullscreen mode on iOS. I don't need that, I need my controls around the video being played.

Is there a way to prevent that?

答: Assuming you already found an answer but for other people looking at this in the future, I suspect the issue was your capitalization of playsinline - in React you have to provide it as playsInline in order for it to be applied correctly, but that prop should prevent iOS from forcing videos into fullscreen when they start playing.

Body:
I am making a web app with video playback and custom controls: a Next Video button and a Previous Video Button. My component looks like this:

const videos = [
    'https://d3t1nqlebka5eu.cloudfront.net/videos3/82818a63-1972-4e39-b296-9cd3b85b0b39.mp4',
    'https://d3t1nqlebka5eu.cloudfront.net/videos3/dd4dd6c5-95b7-41c2-b131-7b62392ad1b5.mp4',
    'https://d3t1nqlebka5eu.cloudfront.net/videos3/29812506-e67d-4cab-b2b3-82461a4eadf1.mp4',
]

function App() {

    const [videoIndex, setVideoIndex] = useState(0);
    const h1Ref = useRef<HTMLVideoElement>(null);

    return (

            <DivButton onClick={() => {
                setVideoIndex(getPrevIndex(videoIndex));
                h1Ref.current!.load();
            }}>
                Prev
            </DivButton>
            {' '}
            <DivButton onClick={() => {
                setVideoIndex(getNextIndex(videoIndex));
                h1Ref.current!.load();
            }}>
                Next
            </DivButton>

                <video id="video_player" autoPlay muted loop playsinline preload="" ref={h1Ref}>
                    <source id="video_player_source" src={videos[videoIndex]} type="video/mp4"/>
                </video>

    );
}

The problem is this: when I click Next or Prev buttons, the videos do switch between one another, but after every switch they are entering fullscreen mode on iOS. I don't need that, I need my controls around the video being played.

Is there a way to prevent that?


问:
How to write a simple pine-script that plots portfolio balance
I am trying to run a simple script that would just allow me to back test from/to a certain date for a stock. Just to keep it simple, lets say the startdate = Jan, 1, 2010 and I have $100,000 to invest into AAPL.

forloop(stardate, +10 min incremenets,

{
   if (5 day sma == some condition)
       buy as many AAPL stocks as balance allows

if (stockprice == some condition)
       sell all stocks
   }
then plot portfolio balance if buy/sell happened.

If anyone can help me out or at least point me in the right direction I would greatly appreacite

答:
I think Pine Script Strategies is what you need.

They plot the portfolio balance (equity curve) automatically.

Screenshot taken from RSI Divergence Indicator strategy

Detailed information about Strategies can be found on Kodify

Or if you're a visual learner, there are several YouTube videos on strategies and backtesting, like this one.


问:
Can I catch specific exceptions globally in a Razor Page (all handler methods) and include them in ModelState?
I'd like to allow all handler methods in a Razor Page to be wrapped by some sort of logic to handle specific exceptions that are more or less validation exceptions.

I've tried the following, but still get the developer exception page:

```<code>    public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
    {
        try
        {
            await next();
        }
        catch(NotImplementedException ex)
        {
            _logger.LogWarning(ex, ex.Message);
            ModelState.AddModelError(string.Empty, "Oops... this isn't all done yet.");
            context.Result = Page();
        }
        catch (DomainValidationException ex)
        {
            ModelState.Include(ex.Results);
            context.Result = Page();
        }
    }
</code>```

The exception does not appear to bubble up from the await next() call and is handled in aspnetcore somehow.

答:
It turns out that the next returns a result that needs to be inspected to get the exception and return the result.

The final implementation looks something like this:

```<code>public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
    var result = await next();

    if (result.Exception != null)
    {
        if (result.Exception is NotImplementedException nex)
        {
             result.ExceptionHandled = true;
            _logger.LogWarning(nex, nex.Message);
            ModelState.AddModelError(string.Empty, "Oops... this isn't all done yet.");
        }
        else if (result.Exception is DomainValidationException dex)
        {
            result.ExceptionHandled = true;
            ModelState.Include(dex.Results);
        }

        if (result.ExceptionHandled)
        {
            result.Result = Page();
        }
    }
}
</code>```

Body:
I'd like to allow all handler methods in a Razor Page to be wrapped by some sort of logic to handle specific exceptions that are more or less validation exceptions.

I've tried the following, but still get the developer exception page:

    public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
    {
        try
        {
            await next();
        }
        catch(NotImplementedException ex)
        {
            _logger.LogWarning(ex, ex.Message);
            ModelState.AddModelError(string.Empty, "Oops... this isn't all done yet.");
            context.Result = Page();
        }
        catch (DomainValidationException ex)
        {
            ModelState.Include(ex.Results);
            context.Result = Page();
        }
    }

The exception does not appear to bubble up from the await next() call and is handled in aspnetcore somehow.

Body:
It turns out that the next returns a result that needs to be inspected to get the exception and return the result.

The final implementation looks something like this:

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
    var result = await next();

    if (result.Exception != null)
    {
        if (result.Exception is NotImplementedException nex)
        {
             result.ExceptionHandled = true;
            _logger.LogWarning(nex, nex.Message);
            ModelState.AddModelError(string.Empty, "Oops... this isn't all done yet.");
        }
        else if (result.Exception is DomainValidationException dex)
        {
            result.ExceptionHandled = true;
            ModelState.Include(dex.Results);
        }

        if (result.ExceptionHandled)
        {
            result.Result = Page();
        }
    }
}


问:
How to append output to the end of a text file
How do I append the output of a command to the end of a text file?</p>

答: Use the >> operator to append text to a file.


问:
OrientDB SQL - How to unwind multiple attributes from an inline collection
Suppose there is a document with an inline collection of objects, as in the example below:

```<code>{ "name": "Alice",
  "children": [{ "name": "Bob", "age": 3 }, { "name": "Charlie", "age": 7 }]
}
</code>```

I'd like to obtain one row per item in the collection, and each inner attribute as a separate column, such as this:

```<code>| name    | childName | childAge |
| Alice   | Bob       | 3        |
| Alice   | Charlie   | 7        |
</code>```

I tried the following query, but it generates a Cartesian product:

```<code>select name, children.name as childName, children.age as childAge
from Employee
unwind childName, childAge
</code>```

I've also managed to extract each child with the expand and flatten functions, but without any reference to its parent.

答:
I want to do the same thing.

The closest I can find in ODB is separating the children into vertices like in this question: OrientDB: How to flatten nested heirarchy into a single record

I would prefer to do it how mongo handles it (Not exactly what I want, but the principal is there.): MongoDB unwind multiple arrays

Failed attempts:

select name, children from Test UNWIND children
result from query 1

select value.name, value.age from (select expand(children) from Test)
result from query 2
If there was a link to the parent this would work, but value.$parent returns empty.

Body:
Suppose there is a document with an inline collection of objects, as in the example below:

{ "name": "Alice",
  "children": [{ "name": "Bob", "age": 3 }, { "name": "Charlie", "age": 7 }]
}

I'd like to obtain one row per item in the collection, and each inner attribute as a separate column, such as this:

| name    | childName | childAge |
| Alice   | Bob       | 3        |
| Alice   | Charlie   | 7        |

I tried the following query, but it generates a Cartesian product:

select name, children.name as childName, children.age as childAge
from Employee
unwind childName, childAge

I've also managed to extract each child with the expand and flatten functions, but without any reference to its parent.


问:
Cannot find -llibmysqld Collect2.exe: error: ld returned 1 exit status
When i was running qt application, it gives these issues. Compile output   screenshot is here. I'm using Qt\5.15.0, mingw81_32, MySQL Connector C 6.1.  Anyone have idea about this? </p>

答: I got this error because of my previous server. Check answer here Check answer here.  </p>