Categories
discuss

Android Test Module (Gradle Plugin 1.3) doesn’t work: “debug-classes not found”

I’m attempting to set up a unit test module as described in the android studio blog post. However, doing a gradle build fails telling me “Configuration with name ‘debug-classes’ not found”. Debug is the name of the targetVariant it’s trying to build, but I don’t understand what is going wrong here.

Here’s my test module’s gradle file.

apply plugin: 'com.android.test'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

targetProjectPath ':app'
targetVariant 'debug'
}    

This is the blogpost describing the new test module functionality. http://android-developers.blogspot.com/2015/07/get-your-hands-on-android-studio-13.html

I’m using the Gradle plugin v1.3.0

Answer

I was also curious about separating app code and test code and i had hard time to figure it out. I look at the stack trace and found the DependencyManager (line 238) having a TODO to fix that in gradle.

1) You are right about the build flavors.You have to enter the correct variant

targetVariant '<flavor>Debug'

e.g.

targetVariant 'flavor1Debug'

2) You also need to change you targetProjectPath’s module build.gradle. Add the following snippet:

android {

    // ...

    publishNonDefault true

    // ...

}

which publishes all build variants! It its disabled by default due to some limitations of gradle.

Categories
discuss

Why doesn’t double.class equal java.lang.Double.class?

Since the primitive double is represented with the java.lang.Double class, shouldn’t double.class equal java.lang.Double.class? (This of course also happens on other primitive types too)

System.out.println(double.class == Double.class);

Output:

Result: false

Answer

Double.class is the class object corresponding to the wrapper type Double. double is actually not a class, but double.class is the object used in reflection to indicate that an argument or return type has primitive type double.

Categories
discuss

How to import GcmListenerService in android studio?

I am creating android application ‘GoogleCloudMessaging’. I Have found many that ‘GcmListenerService’ is being used and the old method ‘GCMIntentService’ is now deprecated. I have already install the Google Play service and add it into the dependency. But when i try to import

 import com.google.android.gms.gcm.GcmListenerService;

it gives error “cannot resolve symbol.” How can I import the Class? I refer https://developers.google.com/android/reference/com/google/android/gms/gcm/GoogleCloudMessaging and https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmListenerService.html#GcmListenerService() and follow the things but still unable to solve the problem.

Answer

If you have already added Google Play Services to your dependencies, the issue might be its version.

Try to update the line(in your build.gradle) to:

compile 'com.google.android.gms:play-services:7.5.0'

Then sync your project.

Categories
discuss

Can Random.nextgaussian() sample values from a distribution with different mean and standard deviation?

This is a combined Java and basic math question. The documentation from Random.nextGaussian() states that it samples from a normal distribution with mean 0 and standard deviation 1. What if I wanted to sample from a normal distribution with a different mean and variance?

Answer

The short answer is

Random r = new Random();
double mySample = r.nextGaussian()*desiredStandardDeviation+desiredMean;

For example this answer is given here: http://www.javamex.com/tutorials/random_numbers/gaussian_distribution_2.shtml

I didn’t really understand why this worked, but after looking into it a bit I think I figured it out. The mean of the sample point is 0, and the standard deviation is 1; that means that the original sample is also its own z-score ( https://en.wikipedia.org/wiki/Standard_score ). To quote from wikipedia “The absolute value of z represents the distance between the raw score and the population mean in units of the standard deviation”. The formula is z=(x-mean)/stdev, so with the default values z=x. If we wanted to retain the z score for the sample but change the mean and stdev what would we do?

z*stdev + mean = x’ where z=x, and x’ represents the sample from the distribution with the desired mean and standard deviation.

Categories
discuss

Could we iterate over the complete set of objects in Amazon S3

I have tried to print the metadata of all the objects in S3 bucket. However, it does not return the results of more than 1000 objects. I have tried implementing the objectListing.isTruncated() and it did not help. Here is a sample code of what I did to list more than 1000 objects.

 ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
            .withBucketName(bucketName);
    ObjectListing objectListing;
    do {
        objectListing = s3client.listObjects(listObjectsRequest);
        for (S3ObjectSummary objectSummary :
                objectListing.getObjectSummaries()) {
            System.out.println( " - " + objectSummary.getKey() + "  " +
                    "(size = " + objectSummary.getSize() +
                    ")");

            listObjectsRequest.setMarker(objectListing.getNextMarker());
        }
        listObjectsRequest.setMarker(objectListing.getNextMarker());
    } while (objectListing.isTruncated());

Answer

This solved my problem. I had setup a marker and truncated my list and was able to print all the objects (more than 1000).

 ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
     .withBucketName(bucketName);
 ObjectListing objectListing;
 do {
     objectListing = s3.listObjects(listObjectsRequest);
     System.out.println("Enter the path where to save yout file");
     Scanner scan = new Scanner(System.in);
     String path = scan.nextLine();
     fileOne = new File(path);
     fw = new FileWriter(fileOne.getAbsoluteFile(), true);
     bw = new BufferedWriter(fw);
     bw.write("Writing data to file");
     bw.write("n");
     for (S3ObjectSummary objectSummary: objectListing.getObjectSummaries()) {
         String key = objectSummary.getKey();
         String dummyKey = key.substring(2);
         if (dummyKey.equalsIgnoreCase("somestring")) {
             S3Object s3object = s3.getObject(new GetObjectRequest(bucketName, key));
             BufferedReader reader = new BufferedReader(new InputStreamReader(s3object.getObjectContent()));
             String line;
             int i = 0;
             while ((line = reader.readLine()) != null) {
                 if (i > 0) {
                     bw.append(line + "," + s3object.getKey().substring(0, 2));
                     bw.append(objectSummary.getLastModified().toString());
                     bw.newLine();
                 }
                 i++;
                 System.out.println(line);
             }
         }
         //                    bw.close();
     }
     listObjectsRequest.setMarker(objectListing.getNextMarker());
 } while (objectListing.isTruncated());
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..