How do you change apk file name? - Android Studio

I have tried this :
Code:
buildTypes{
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = file("$project.buildDir/apk/test.apk")
}
}
But it doesn't work with version of gradle I have:
Error15, 0) Gradle DSL method not found: 'buildTypes()'
Possible causes:<ul><li>The project 'HexapodController' may be using a version of Gradle that does not contain the method.
Gradle settings</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>

Related

XML parsing-best method, general discussion

I am relatively new to programing and have been teaching myself as I go. I am trying to now integrate ESPN's API into my app which outputs XML data. I have done enough research to understand that I need to use an XML parser and that the XML can be displayed as a list view or web view by adding HTML markup.
I would like this thread to become a general discussion for all new developers on what XML parsing is and what it does. How it works, the code behind it etc.
I am currently trying to modify a code snippet from the developer.google.com website.
Android includes built in libraries for XML Parsing.
You can see a minimal use of the library here:
Code:
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class SimpleXmlPullApp
{
public static void main (String args[])
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput( new StringReader ( "<foo>Hello World!</foo>" ) );
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+xpp.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+xpp.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+xpp.getText());
}
eventType = xpp.next();
}
System.out.println("End document");
}
}
So essentially, you can grab the xml from ESPN, save it to a file, parse it with that library, and output as desired.
Full details here: http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
the fastest way I know is the parser written in c/c++ and compiled with ndk.
bitpushr said:
Android includes built in libraries for XML Parsing.
So essentially, you can grab the xml from ESPN, save it to a file, parse it with that library, and output as desired.
Full details here: http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
Click to expand...
Click to collapse
I will have to try out this code. Because I am learning as I go there are many things in java I don't yet understand which ultimately make it a lot harder to accomplish tasks but I am slowly catching on
If you want to do this in a .NET (Windows x86/64, Windows Mobile, Windows Phone) environment, or a Linux MONO environment then the following will carry out the bare minimum of parsing.
Assuming you have the data in an XML file :- PARAMS.XML in the same folder as the program, created similar to this:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<PARAMS>
<Library>TESTLIB</Library>
<Source>C:\RetData\</Source>
</PARAMS>
Then the following C# code will read and extract the parameters:
Code:
using System.Xml;
string LibName,RetDir;
XmlReader xrdr = XmlReader.Create(Application.StartupPath+"\\PARAMS.xml");
xrdr.ReadToFollowing("Library");
Libname=xrdr.ReadElementContentAsString();
xrdr.ReadToFollowing("Source");
RetDir = xrdr.ReadElementContentAsString();
xrdr.Close();
After executing this code then:
LibName = "TESTLIB"
RetDir = "C:\RetData\"
CAVEAT:
I mentioned that this is the bare minimum. An XmlReader object is a forward only reader. Also, this code has no error checking.
In this case the elements must be read in the order they occur or the reader will encounter a null element and throw an error.

Build Variants / APK naming

So I can't seem to find an answer to get this to work the way i want, hoping someone here may know...
I have my gradle setup with different build variants and it works fine to switch between them or generate signed apk for the chosen variant. However what I'm looking to do (ideally in 1 click) is generate each variant's apk and name it accordingly with the version number and variant name.
Any ideas?
I've tried the following snippet
Code:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = outputFile.name.replace('.apk', "-${versionName}.apk")
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
but no joke, if i went to modify it..it froze android studio. thanks!

Error:(8, 0) Gradle DSL method not found: compile()

I'm trying to reduce google play services' impact on APK size. I get the following error when i try to synchronize the gradle proyect. I would be very thankful if somebody can help me with this problem.
Error8, 0) Gradle DSL method not found: 'compile()'
Possible causes:
- The project 'MorphingTunnelFreeLauncher' may be using a version of Gradle that does not contain the method. Gradle settings
- The build file may be missing a Gradle plugin.
The changes in the gradle code looks like this:
- build.gradle in googleplayservices_lib
apply plugin: 'com.android.library'
android {
compileSdkVersion 9
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 9
}
buildTypes {
release {
minifyEnabled true //changed
shrinkResources true //changed
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/google-play-services.jar')
}
- build.gradle in the app itself:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
compile 'com.google.android.gmslay-services-ads:6.5.+'//changed
}
}
allprojects {
repositories {
jcenter()
}
}

android studio problem

Hi, i have the next problem, when i open a project in android stuidio, appear the next message
Error:Could not create an instance of Tooling API implementation using the specified Gradle installation 'C:\Program Files\Android\Android Studio\gradle\gradle-2.8'.
what could be? and What i can do?
Thanks for all
Have you tried updating Android Studio?
Also you could show build.gradle file for this project.
klisiecki said:
Have you tried updating Android Studio?
Also you could show build.gradle file for this project.
Click to expand...
Click to collapse
this show the file build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Hi!
Try to use last version of android studio gradle plugin.
Just change line
Code:
classpath 'com.android.tools.build:gradle:1.5.0'
to
Code:
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'

Unable to resolve all dependencies in android studio 3.0

I am getting these errors while syncing gradle:-
Error:Unable to resolve dependency for ':[email protected]/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Error:Unable to resolve dependency for ':[email protected]/compileClasspath': Could not resolve com.android.support:design:26.1.0.
Error:Unable to resolve dependency for ':[email protected]/compileClasspath': Could not resolve com.android.support.test:runner:1.0.1.
Error:Unable to resolve dependency for ':[email protected]/compileClasspath': Could not resolve junit:junit:4.12.
Error:Unable to resolve dependency for ':[email protected]/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.1.
METHODS TRIED
i have tried adding GOOGLE MAVEN REPO, mavencentral all with url & without url.
i have tried deleting .gradle folder from C:\Users\<username>/.gradle.
i have tried gradle offline work and online work, both end up with same error message.
tried clean project & rebuilding.
tried INVALIDATE CACHE & RESTART.
tried degrading the android studio version.
I AM USING WINDOWS 64BIT WITH 4GB OF RAM AND DUAL CORE 2.0 GHZ PROCESSOR, AND ANDROID VERSION 3.0, GRADLE VERSION 4.1 & 4.3(LATEST), I HAVE INSATLLED ALL THE NECESSARY TOOLS & EVERYTHING UPDATED IN SDK MANAGER. ANDROID SUPPORT REPOSITORY & GOOGLE OFFLINE REPOSITORY BOTH INSTALLED.
WHENEVER I TRY TO SYNC IT WITH OFFLINE WORK IT END UP WITH ERROR (NO CACHED VERSION OF THIS (DEPENDENCY IS FOUND), AND WHENEVER I TRY TO SYNC WITH ONLINE WORK, THE ERRORS ARE SAME LISTED ABOVE IN BOTH CASES.
I HAVE TRIED EVERYTHING FROM STACK OVER FLOW & YOUTUBE.
BUILD.GRADLE PROJECT:MY APPLICATION.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
BUILD.GRADLE MODULE:APP
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.vipinsaini.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
CAN ANYONE PLZ HELP ME SOLVE THIS ISSUE. I am new to android studio plz omit mistakes.
Add google() to allprojects node in your root build.gradle file
allprojects {
repositories {
jcenter()
google()
}
}
Hey,
I have a same problem. I tried to do your solution, but already exist this code in build.gradle file.
I will be happy to another solution.
Thanks.
Try to Invalidate Cache/Restart that got the problem fixed for me
Unable to Resolve Dependencies
After much research and headache... Go to File\Settings\Gradle. Deselect the "Offline work" box. Now you can connect and download any necessary or missing dependencies.
Worked, thank you.
i tried invalidate and restart then delete .gradle file then uncheck the offline work but no use not clear the appcompact error

Categories

Resources